idleTimeout not working as expected on minimal WebSocket server setup
Hi,
First of all, thank you for this incredible project — it's truly a masterpiece.
I’m facing an issue where the idleTimeout option doesn’t seem to work as expected. I’ve tested with both wscat and Postman as WebSocket clients, but the connection never closes due to inactivity, even after the specified timeout period.
Setup Details:
- Running on
localhost - OS: macOS
- Node.js version: v22.16.0
- uWebSockets.js version: github:uNetworking/uWebSockets.js#v20.52.0
What I Tried:
Left the client idle (no message sent) Verified the client isn’t sending any background frames Reproduced using wscat and Postman on localhost No proxy or middleware like NGINX involved If there’s anything I’m missing or if there are known conditions under which idleTimeout doesn’t work, I’d appreciate any guidance.
Thanks, help appreciated!
Code:
import uWS from 'uWebSockets.js';
uWS.App().ws('/*', {
idleTimeout: 10,
open: (ws) => {
console.log('Connected');
},
message: (ws, message, isBinary) => {
console.log('Message received');
},
close: (ws, code, msg) => {
console.log(`Closed: code=${code}, message=${Buffer.from(msg).toString()}`);
}
}).listen(9001, (token) => {
if (token) {
console.log('Listening on port 9001');
} else {
console.error('Failed to listen');
}
});
Ran into this today as well. Have confirmed this regression by sending an emit to an active socket every few seconds to keep the connection alive. My timeout time setting is currently disabled but still falls back to roughly 120 seconds. My config:
idleTimeout: 0
What version did this last work?
I added a smoke test for this in CI and it passes:
Starting timeout test: Keeping connection open for timeout WebSocket closed with code: 1006 and reason: WebSocket timed out from inactivity Test passed: WebSocket timed out from inactivity Client WebSocket closed with code: 1006 and reason: <Buffer > All tests passed.
What if you add sendPingsAutomatically: false
Here is your example with sendPingsAutomatically: false
Listening on port 9001 Connected Closed: code=1006, message=WebSocket timed out from inactivity
What version did this last work?
I tried v20.51.0 as well.
idleTimeout: 0
Does this keep the connection open for you indefinitely in a live environment? Testing locally seems to work. On an EC2 in a live environment this parameter gets ignored for some reason. The only way I can keep the connection alive is if I use long polling on the client.