socket.io-stream
socket.io-stream copied to clipboard
Memory leak prevention / warnings
When I used socket.io-stream for a bigger project where I did things like pipe multiple streams and sometimes streams where not handled on the end I ran into lots of little memory leak issues. I really had to dive into how socket.io-stream works to figure out what was going wrong. So I'd like to come up with ways to make this easier for other people. One of the "invisible" problem areas is that each socket.io-stream socket stores references to socket.io-stream streams it uses. When streams are not handled these streams keep piling up. This is especially problematic when you put streams in flowing mode and they already have a chunk of data in their buffer.
- One first thing I would do is log (using debug) the amount of stored streams, this way people see this growing number. Preferably when the streams are added.
- Another idea might be to give a warning when a certain amount is reached, like Node.js's max listeners warning.
- Could it be that streams don't get removed when an error occurs? I wrote error handlers on streams that would manually
end()
anddestroy()
that stream.