-
Notifications
You must be signed in to change notification settings - Fork 356
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
setTimeout to emit drain in websocket.js:175 causes following message delayed 1s when tab in background #649
Comments
Hi! Here's what I have been able to reproduce: // client-side
const socket = io();
let count = 0;
setInterval(() => {
socket.emit("test", ++count, new Date());
}, 1000);
// server-side
io.on("connection", (socket) => {
socket.on("test", (count, date) => {
console.log(count, date.substring(11), new Date().toISOString().substring(11));
})
});
Happens on Chrome (87.0.4280.88) and Firefox (84.0) / Ubuntu. Is this the behavior you are describing? In that case, since the timestamp is the same on the client and on the server, I'd say the issue comes from the |
Yes, this is the case. engine.io-client/lib/transports/websocket.js Line 180 in 63939e6
I want to know if it can be optimized. |
Hello! We've ran into a similar time throttling issue where the server or the client will get From the client perspective, after the tab has been backgrounded for around 5 minutes the setTimeout of zero in the Our workaround is to change the setTimeout to a Promise.resolve().then() which will still block writes until the next tick without Chrome throttling the timer to death. We have good results so far. We've also had a hard time reproducing this issue because every time we tried to create a small test the timer does not seem to throttle. I suspect Chrome only aggressively throttles on tabs that are consuming higher resources. |
@darrachequesne With Chrome now throttling setTimeout calls and other browsers soon following suit, can the setTimeout be removed? Why is it useful here? |
An immediate setTimeout was used to unblock the WebSocket write. Unfortunately, this setTimeout can be throttled by browsers when the tab is backgrounded. This can lead to missed pong responses to server pings, which eventually leads to disconnection. Related: #649
This should be fixed by f30a10b, included in Big thanks to @hyperlink for his PR 👍 |
You want to:
Current behaviour
When using Chrome or Safari and putting tab into background, timer is delayed to ensure at least 1s interval. And it causes that
later message is delayed 1s.
Steps to reproduce (if the current behaviour is a bug)
Expected behaviour
sent message is not delayed
Setup
Other information (e.g. stacktraces, related issues, suggestions how to fix)
I try to remove this
setTimeout
but connection is disconnected. So I want to know ifsetTimeout
can be removed?The text was updated successfully, but these errors were encountered: