question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

uWS support is a bit broken on Windows

See original GitHub issue

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' });

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:21
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
igabeszcommented, 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);
	}
4reactions
Hughp135commented, Jan 19, 2018

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)
...
Read more comments on GitHub >

github_iconTop Results From Across the Web

Glass Shattered by Bricks on Broadway - West Side Rag
This is the crisis of the moment — literally, broken windows.” The police are waiting to view security tapes, he said, back to...
Read more >
Top 10 Best Window Screen Repair near Upper West Side ...
Reviews on Window Screen Repair in Upper West Side, Manhattan, NY - Cityproof Windows, Bensons Windows Repair, A&J Window Repair, CitiQuiet Soundproof ...
Read more >
Computer Repair in New York | Upper West Side - uBreakiFix
Best Computer Repair Services in New York, NY, Guaranteed! Call (212) 903-4349 & Schedule your Mac or PC repair Today!
Read more >
micros® Workstation 4 Setup Guide - Oracle Help Center
The MICROS Workstation 4 is a diskless Windows CE client, based on a ... the 8700 and 9700 POS Applications when the WS4...
Read more >
Student Affairs - University of Western States
The office of student affairs helps all UWS students pursue academic excellence and cultivate meaningful communities by supporting co-curricular service and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found