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
Emitting to old connections on browser refresh and retaining old connections #2424
Comments
You need to clear the interval on disconnect with clearInterval.
This should stop it from holding on to the old connections. |
@StevenBock Ah OK .. yep that's all good - thanks! I have the same issue with this other example. I'd like to tail a file and send each new line to the client. Using the npm 'tail' module this code works OK, but has that holding onto old connections problem:
Somehow I need to dispose tail event (tailTmpFile.on) when the socket disconnects. |
@StevenBock OK great - got it. This code removes the event listener on disconnect.
Thank you kindly for taking the time to reply, it really set me in the right direction. Cheers. |
Glad to help! |
Hi,
I have a simple socket.io server test setup that is sending the current Date() to a single client.
Every 1 second the server sends (emits) the Date() to one client.
If I refresh the browser window, I still have one connection but the server emits to two connections.
If I refresh the browser window, I still have one connection but the server emits to three connections.
If I refresh the browser window, I still have one connection but the server emits to four connections.
And so on and so on...
Even after several hours the disconnected clients are still being emitted to by the server.
I was expecting the server to drop/close the old connections without a client attached.
Is this expected behavior?
I'm using Socket.io v1.4.5 with Node v5.4.1
Here's a code sample:
Here's the console.log output when I refresh the browser every 2 seconds.
You can see the socket.conn.id for each browser refresh is being emitted to.
Even after many hours and no connected clients (browsers) the old connections are still being emitted to.
The text was updated successfully, but these errors were encountered: