Error during WebSocket handshake
The server did not answer the Upgrade request with a valid 101. The end of the console message says what was wrong.
What it means
The server must answer Upgrade: websocket with 101 Switching Protocols plus Upgrade, Connection and Sec-WebSocket-Accept (RFC 6455 § 4.2.2). Chrome shows this error for any other answer. DNS, port and TLS did work; had they failed, the message would be Error in connection establishment.
JavaScript gets only close with code 1006. The cause is at the end of the console message.
How to fix it
Unexpected response code: NNN. The status is not 101:
200: a proxy droppedUpgradeand the backend served a page, or a wrong path hit a SPA'sindex.html.400,426: usually the same dropped header. Socket.IO also returns400on a client/server version mismatch.403:Originor credentials rejected; many libraries accept only the server's own origin by default.404: wrong path;/wsand/ws/can differ.301,302: a redirect (ws://→wss://, trailing slash). Browsers do not follow it; use the final URL.502,503,504: the application behind the proxy is not answering.
nginx does not pass Upgrade by default. For 200 and 400:
location /ws {
proxy_pass http://app;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
The full answer:
curl -i -N --http1.1 --max-time 5 \
-H "Connection: Upgrade" \
-H "Upgrade: websocket" \
-H "Sec-WebSocket-Version: 13" \
-H "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==" \
https://example.com/ws
Keep --http1.1: HTTP/2 has no Upgrade, and curl prefers it over TLS. For a 403, add -H "Origin: https://your-site.example": browsers send Origin, curl does not.
Incorrect 'Sec-WebSocket-Accept' header value or 'Sec-WebSocket-Accept' header is missing. The value is base64(SHA-1(key + fixed GUID)). A hand-written server usually decodes the key before hashing, sends hex, or mistypes the GUID. Check with the Sec-WebSocket-Accept calculator; for the key above: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=.
Status 101, a header wrong:
'Upgrade' header is missing,'Connection' header value must contain 'Upgrade': the server omitted them or a proxy stripped them.Sent non-empty 'Sec-WebSocket-Protocol' header but no response was received:new WebSocket(url, ['v1'])and the server chose no subprotocol. Return one of the offered names or drop the second argument.Response must not include 'Sec-WebSocket-Protocol' header if not present in request: the server returned an unrequested subprotocol.
net::ERR_…. The reply was cut off or was not HTTP. Check the port and the server log.
See it on your own traffic
Solpuga records the Upgrade request with its headers: check Upgrade, Connection, Sec-WebSocket-Key and Origin. Solpuga answers the browser's handshake itself and connects to the server separately. A refused upgrade shows as WebSocket Upgrade Failed, without the server's status, and the browser gets 1006 instead of this message. Read the server's answer with curl.
See Capture & Inspect Traffic for how Solpuga records a stream.
Tool for this page
Sec-WebSocket-Accept calculatorTurn a Sec-WebSocket-Key into the Sec-WebSocket-Accept a server must answer with, and check a pair you already have.Related
- WebSocket closed with status code 1006 — how to find the causeThe connection died with no Close frame. Four causes, and how to tell them apart.
- The stream dies after 60 seconds: proxy_read_timeoutA stream that dies on the same second is a timeout. Default values in nginx, ALB, Cloudflare, Heroku and Envoy, and why a heartbeat is safer.