Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uWS support is a bit broken on Windows #3100

Closed
1 of 2 tasks
luffs opened this issue Oct 30, 2017 · 8 comments
Closed
1 of 2 tasks

uWS support is a bit broken on Windows #3100

luffs opened this issue Oct 30, 2017 · 8 comments
Milestone

Comments

@luffs
Copy link

luffs commented Oct 30, 2017

You 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

  1. Make a server, listen to "test" event. Start with env DEBUG=socket.io*
  2. Open a browser, emit "test" event to server; everything is fine.
  3. Open same page in another tab. You should now have 2 connected clients.
  4. Emit "test" event in browser from the console. There is now a huge delay until the event listener in step 1 is fired.
  5. 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.
  6. 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' });

@afterx
Copy link

afterx commented Nov 6, 2017

I seem to be having the same issue on windows 7 latest chrome. Updating my krama timeout made it run, but extremely slow.

06 11 2017 07:30:**23**.179:INFO [launcher]: Starting browser ChromeHeadless
06 11 2017 07:30:**32**.444:WARN [karma]: No captured browser, open http://localhost:9876/
06 11 2017 07:30:43.738:INFO [HeadlessChrome 0.0.0 (Windows 7 0.0.0)]: Connected on socket 

@Hughp135
Copy link

Hughp135 commented Nov 18, 2017

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:

client emits 1
server immediately replies 1
client emits 2
server immediately  replies 2

But when 2 clients are connected, you get this random offset:

client emits 1
....
client emits 2
server immediately  replies 1 after receiving 2
client emits 3
server immediately replies 2 after receiving 3
... a few seconds pass
server eventually replies 3

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.

setInterval(()=> {}, 50)

With this code you would see something like this (when2 clients are connected).

client emits 1
server replies 1 (<=50ms later)
client emits 2
server replies 2 (<=50ms later)
...

@ulikus
Copy link

ulikus commented Dec 5, 2017

Same applies to socket,io.

@navelencia
Copy link

I get the exact same behavior. Would be nice to have a fix with uws.

darrachequesne added a commit to socketio/engine.io that referenced this issue Dec 29, 2017
@igabesz
Copy link

igabesz commented Jan 19, 2018

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:

	if (/^win/.test(process.platform)) {
		console.warn('Starting uws bug-hack interval under Windows');
		setInterval(() => {}, 50);
	}

@yaneony
Copy link

yaneony commented Feb 6, 2018

Same happens to me on Windows 7 machine, where is working well on Debian (with same code).

xPaw added a commit to thelounge/thelounge that referenced this issue Feb 23, 2018
@zz1985summer
Copy link

Thank you so much,this issue confued me serval days,finally got your tips!!thank you !

@darrachequesne
Copy link
Member

For future readers: ws was reverted as the default WebSocket server implementation in socket.io@2.1.0.

Documentation: https://socket.io/docs/v3/server-installation/#Other-WebSocket-server-implementations

@darrachequesne darrachequesne added this to the 2.1.0 milestone Feb 19, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants