"Session ID unknown" after handshake on high server load [Socket.io 1.0.6]
See original GitHub issueI am running a multi-node server (16 workers running Socket.io 1.0.6; accessed via Nginx, configured as a reverse proxy supporting sticky sessions) for ~ 5k users. While the load of the server is low (2~3 on a 20 core server / 2k users), everyone is able to connect instantly. When the load of the server gets higher (5~6 / 5k users), new users are not able to connect and receive data instantly. In this case, it takes 2~4 handshakes for the users to connect succesfully.
This is what happens (high load):
- User opens the website; receives HTML and JS
- User’s browser attempts to initialize a socket.io connection to the server (
io.connect(...)
) - A handshake request is sent to the server, the server responds with a SID and other information (
{"sid":"f-re6ABU3Si4pmyWADCx","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}
) - The client initiates a polling-request, including this SID:
GET .../socket.io/?EIO=2&transport=polling&t=1408648886249-1&sid=f-re6ABU3Si4pmyWADCx
- Instead of sending data, the server responds with 400 Bad Request:
{"code":1,"message":"Session ID unknown"}
- The client performs a new handshake (
GET .../socket.io/?EIO=2&transport=polling&t=1408648888050-3
, notice the previously received SID is omitted) - The server responds with new connection data, including a new SID: (
{"sid":"DdRxn2gv6vrtZOBiAEAS","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}
) - The client performs a new polling request, including the new SID:
GET .../socket.io/?EIO=2&transport=polling&t=1408648888097-4&sid=DdRxn2gv6vrtZOBiAEAS
- The server responds with the data that is
emit
ted in the worker source code.
Depending on the load of the server, it may happen 1~3 times that the server responds with "Session ID unknown"
and the client needs to perform a new handshake before data is actually received.
Issue Analytics
- State:
- Created 9 years ago
- Reactions:7
- Comments:27 (6 by maintainers)
Top Results From Across the Web
Node.js with Socket.io - Long Polling fails and throws "code":1 ...
When I click on the GET or the XMLHttpRequest I can see that the response is "code":1,"message":"Session ID unknown" , which I don't...
Read more >"Session ID unknown" after handshake on high server load [Socket ...
I am running a multi-node server (16 workers running Socket.io 1.0.6; accessed via Nginx, configured as a reverse proxy supporting sticky sessions) for...
Read more >Using multiple nodes | Socket.IO
IO servers, there are two things to take care of: ... experience HTTP 400 errors due to "Session ID unknown"; the WebSocket transport...
Read more >Module ngx_http_ssl_module - Nginx.org
Since version 1.11.0, this directive can be specified multiple times to load certificates of different types, for example, RSA and ECDSA: server {...
Read more >primus - npm
In the above example we automatically create a HTTP server which will listen on port 8080, a primus instance with the websockets transformer...
Read more >Top Related Medium Post
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
for me, it was with nginx ssl http2, and it was polling, so the good config is:
DON’T FORGET TO CONFIGURE CLIENT AS WELL
Making just nodejs backend to use
transport
as websocket protocol won’t do much. socket.io clients are also required to set with the same configuration. So, in my onion below should work:in nodejs:
and in js client:
['websocket', 'polling']
will force socket.io to try webscoket as the first protocol to connect, otherwise fall back to polling (just in case some browsers/clients may not support websockets). For cluster environment, better to use['websocket']
only.