{"action":"created","issue":{"url":"https://api.github.com/repos/nkzawa/socket.io-stream/issues/43","labels_url":"https://api.github.com/repos/nkzawa/socket.io-stream/issues/43/labels{/name}","comments_url":"https://api.github.com/repos/nkzawa/socket.io-stream/issues/43/comments","events_url":"https://api.github.com/repos/nkzawa/socket.io-stream/issues/43/events","html_url":"https://github.com/nkzawa/socket.io-stream/issues/43","id":69356053,"number":43,"title":"'disconnect' causes errors on old streams, memory leak?","user":{"login":"sbull","id":1115369,"avatar_url":"https://avatars.githubusercontent.com/u/1115369?v=3","gravatar_id":"","url":"https://api.github.com/users/sbull","html_url":"https://github.com/sbull","followers_url":"https://api.github.com/users/sbull/followers","following_url":"https://api.github.com/users/sbull/following{/other_user}","gists_url":"https://api.github.com/users/sbull/gists{/gist_id}","starred_url":"https://api.github.com/users/sbull/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbull/subscriptions","organizations_url":"https://api.github.com/users/sbull/orgs","repos_url":"https://api.github.com/users/sbull/repos","events_url":"https://api.github.com/users/sbull/events{/privacy}","received_events_url":"https://api.github.com/users/sbull/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-18T22:39:10Z","updated_at":"2015-04-18T23:01:29Z","closed_at":null,"body":"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.\r\n\r\nI 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?\r\n\r\nThe 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.\r\n\r\nAm I missing something? Thanks."},"comment":{"url":"https://api.github.com/repos/nkzawa/socket.io-stream/issues/comments/94210794","html_url":"https://github.com/nkzawa/socket.io-stream/issues/43#issuecomment-94210794","issue_url":"https://api.github.com/repos/nkzawa/socket.io-stream/issues/43","id":94210794,"user":{"login":"sbull","id":1115369,"avatar_url":"https://avatars.githubusercontent.com/u/1115369?v=3","gravatar_id":"","url":"https://api.github.com/users/sbull","html_url":"https://github.com/sbull","followers_url":"https://api.github.com/users/sbull/followers","following_url":"https://api.github.com/users/sbull/following{/other_user}","gists_url":"https://api.github.com/users/sbull/gists{/gist_id}","starred_url":"https://api.github.com/users/sbull/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbull/subscriptions","organizations_url":"https://api.github.com/users/sbull/orgs","repos_url":"https://api.github.com/users/sbull/repos","events_url":"https://api.github.com/users/sbull/events{/privacy}","received_events_url":"https://api.github.com/users/sbull/received_events","type":"User","site_admin":false},"created_at":"2015-04-18T23:01:29Z","updated_at":"2015-04-18T23:01:29Z","body":"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. :("}}