Trying to understand why WebSocket connections drop during agent login simulation.
Environment is Genesys Cloud US1. Using JMeter 5.6 for load testing.
Goal is to validate agent capacity before peak season. Script simulates 100 concurrent agents logging in.
Each thread executes the login sequence. Then it attempts to establish the WebSocket connection for real-time events.
About 40% of connections fail immediately. The browser console or JMeter debug sampler shows error 1006. No clear reason provided.
The API tokens are valid. Login returns 200 OK. But the socket never stabilizes.
Is there a specific limit on WebSocket handshakes per minute? The documentation mentions rate limits for REST APIs. But WebSocket limits are not clear.
I checked the network tab. The initial handshake succeeds. Then the connection closes abruptly.
Has anyone seen this pattern? Is it a server-side timeout? Or a client configuration issue in JMeter?
Need to know how to tune the test. Or if this indicates a real bottleneck in the platform.
About 40% of connections fail immediately.
Have you tried checking the v2.users.{id}.tokens endpoint before the WS handshake? i think the issue isn’t the socket itself, but the auth token expiring during the load test. our org hit this last week. check token validity first.
3 Likes
This looks like a token scope issue rather than a network drop. The WebSocket handshake requires specific permissions that the default login token might not carry under load.
{
"grant_type": "client_credentials",
"scope": "websockets:connect websockets:read"
}
1 Like
You might want to look at how you’re handling the token refresh cycle in JMeter. It’s not just about the initial scope, but keeping the token alive during the handshake.
The WebSocket client needs a fresh token right before the upgrade. If the token expires during the load spike, the connection drops with a 1006 error. You need to ensure the token is valid at the moment of connection.
try adding a pre-request script to validate the token expiry. if it’s close to expiring, refresh it. this usually fixes the drop rate significantly.
1 Like
Ah, this is a known issue…
Cause:
The 1006 error isn’t usually a network drop. It’s the server killing the connection because the auth token used for the WebSocket handshake is either expired or lacks the specific websockets:connect scope. JMeter threads often reuse tokens from a pool that expires faster than your test duration. Genesys Cloud validates the token signature and scope on every WS upgrade. If the scope is missing, the server rejects the upgrade and closes the socket. This is why 40% fail. The default login token often doesn’t carry the WS scopes under load.
Solution:
Stop using the standard user token for the WS handshake in your script. Switch to a service account with client_credentials flow. This gives you a static, long-lived token with the exact scopes needed. You’ll avoid the expiration race condition entirely.
Here’s how to get the token in Python. Run this once and pass the token to JMeter as a variable.
import requests
def get_ws_token(client_id, client_secret):
url = "https://api.mypurecloud.com/oauth/token"
headers = {"Content-Type": "application/x-www-form-urlencoded"}
data = {
"grant_type": "client_credentials",
"scope": "websockets:connect websockets:read"
}
response = requests.post(url, headers=headers, data=data, auth=(client_id, client_secret))
return response.json()["access_token"]
# Use this token in your JMeter WebSocket sampler
token = get_ws_token("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET")
Make sure the service account has the Websocket capability enabled in the UI. Without it, you’ll still get 403s. Also, check your JMeter WebSocket sampler settings. The connection URL needs to include the tenant ID. If you’re using the wrong region endpoint, the handshake fails silently. Verify the URL matches your environment. US1 is wss://websockets-us-east-1.pure.cloud.com. If you’re hitting US2, you’ll get immediate disconnects. This setup handles 10k agents without breaking. Don’t use user tokens for load testing WS. It’s a recipe for failure.