socket.io-stream icon indicating copy to clipboard operation
socket.io-stream copied to clipboard

'disconnect' causes errors on old streams, memory leak?

Open sbull opened this issue 11 years ago • 2 comments

I'm noticing that when a client disconnects, an error event gets emitted on my server's socket.io-stream even though the server stream has already received an 'end' event. I would have expected that the 'end' event would exclude any further events from happening on my server read stream (except maybe 'close'), and that the stream would be cleaned up. Specifically, I would expect Socket.prototype._onend to do something like stream.destroy() or socket.cleanup(id) to the readable end of my stream.

I might be overlooking something, but isn't this a memory leak? How should I close down my streams, if receiving the 'end' event on them doesn't do the job? Should I manually be calling destroy() on an 'end' handler?

The symptom of this problem is that my server-side readable socket.io-stream receives the commands in Socket.prototype._ondisconnect even after it has "ended", particularly the stream.emit('error', new Error('Connection aborted'));. I wouldn't expect stream that I've already consumed to give me some error event a some future time, just because the client eventually disconnects.

Am I missing something? Thanks.

sbull avatar Apr 18 '15 22:04 sbull

Hmmmm... I'm not sure whose problem this is. It turns out that in my situation, I hadn't actually turned the stream into flowing mode yet, and never got the 'end' event (although I saw it emitted in the debug logs for socket.io:socket and socket.io-stream:socket). So apparently the stream doesn't get cleaned up from the socket unless you've consumed it, and it will throw this error event on disconnect even if it has already received the end event. :(

sbull avatar Apr 18 '15 23:04 sbull

Can you provide a simple snippet to reproduce the issue if possible?

nkzawa avatar Apr 21 '15 18:04 nkzawa