uWS support is a bit broken on Windows
See original GitHub issueYou want to:
- report a bug
- request a feature
Current behaviour
Only in Windows when using uWs: Huge delay between websocket data is parsed, and event is emitted to server event listeners, when more than one client is connected.
Steps to reproduce
- Make a server, listen to “test” event. Start with env DEBUG=socket.io*
- Open a browser, emit “test” event to server; everything is fine.
- Open same page in another tab. You should now have 2 connected clients.
- Emit “test” event in browser from the console. There is now a huge delay until the event listener in step 1 is fired.
- Emit event twice, socket.emit(‘test’, {}); socket.emit(‘test’, {}); and the first event fires directly, and there is a huge delay on the second one.
- Close the second browser tab and emit some events again. The delay is gone.
Expected behaviour
Event emitter should fire within 1-2ms.
Setup
- OS: Windows 10 x64
- browser: tested in both Chrome and Firefox
- socket.io version: 2.0.4
Other information (e.g. stacktraces, related issues, suggestions how to fix)
socket.io:server initializing namespace / +0ms socket.io-parser encoding packet {“type”:0,“nsp”:“/”} +3ms socket.io-parser encoded {“type”:0,“nsp”:“/”} as 0 +0ms socket.io:server creating engine.io instance with opts {“path”:“/socket.io”,“initialPacket”:[“0”]} +1ms socket.io:server attaching client serving req handler +5ms socket.io:server incoming connection with id uLSPqVnrkgVklbmJAAAA +1s socket.io:client connecting to namespace / +2ms socket.io:namespace adding socket to nsp / +0ms socket.io:socket socket connected - writing packet +4ms socket.io:socket joining room uLSPqVnrkgVklbmJAAAA +1ms socket.io:socket packet already sent in initial handshake +1ms user connected <-- FIRST CLIENT CONNECTED socket.io:socket joined room uLSPqVnrkgVklbmJAAAA +3ms socket.io-parser decoded 2[“test”,{}] as {“type”:2,“nsp”:“/”,“data”:[“test”,{}]} +4s socket.io:socket got packet {“type”:2,“nsp”:“/”,“data”:[“test”,{}]} +1ms socket.io:socket emitting event [“test”,{}] +0ms socket.io:socket dispatching an event [“test”,{}] +0ms test {} socket.io:server incoming connection with id QfIEBNCsI5InQCrgAAAB +15s socket.io:client connecting to namespace / +0ms socket.io:namespace adding socket to nsp / +0ms socket.io:socket socket connected - writing packet +1ms socket.io:socket joining room QfIEBNCsI5InQCrgAAAB +0ms socket.io:socket packet already sent in initial handshake +0ms user connected <— ANOTHER CLIENT CONNECTED socket.io:socket joined room QfIEBNCsI5InQCrgAAAB +1ms socket.io-parser decoded 2[“test”,{}] as {“type”:2,“nsp”:“/”,“data”:[“test”,{}]} +5s socket.io:socket got packet {“type”:2,“nsp”:“/”,“data”:[“test”,{}]} +20s <— THIS IS THE PROBLEM, 20sec delay! socket.io:socket emitting event [“test”,{}] +1ms socket.io:socket dispatching an event [“test”,{}] +0ms test {} socket.io:client client close with reason transport close +7s socket.io:socket closing socket - reason transport close +1ms <— DISCONNECTED ONE CLIENT socket.io-parser decoded 2[“test”,{}] as {“type”:2,“nsp”:“/”,“data”:[“test”,{}]} +5s socket.io:socket got packet {“type”:2,“nsp”:“/”,“data”:[“test”,{}]} +1ms socket.io:socket emitting event [“test”,{}] +0ms socket.io:socket dispatching an event [“test”,{}] +0ms test {}
A workaround is to change the wsEngine to ws in the options:
const io = require('socket.io')(httpServer, { wsEngine: 'ws' });
Issue Analytics
- State:
- Created 6 years ago
- Reactions:21
- Comments:8 (1 by maintainers)
Top GitHub Comments
I confirm this issue. I see the same behavior in Win 10 – but it works correctly in the Linux subsystem of Win 10. (Same codebase, just reinstalled node_modules.) I see similar behavior when I connect from a browser or from another Node.js application. The fix from @Hughp135 works for me too:
I’m getting this too! It’s been driving me crazy.
Windows 10. Happens in either chrome or firefox. Does not occur on my macbook.
Basically, with 2 clients connected, some emits are basically ignored until some other code gets triggered on the server, or if nothing happens, the server’s reply can be delayed for several seconds. I have replicated this on a clean project, using express + io.
An example of console logging a counter emitted from client and then sent back from the server. You would normally expect to see something like this:
But when 2 clients are connected, you get this random offset:
I’ve noticed that setting a random interval function on the server can trigger the server to reply faster. E.g. if you add this code randomly anywhere on the server, it will trigger the event on every tick.
With this code you would see something like this (when2 clients are connected).