socketio-file-upload icon indicating copy to clipboard operation
socketio-file-upload copied to clipboard

Possible memory issue

Open r-teplov opened this issue 5 years ago • 2 comments

Hello.

There is possible issue while saving data with write function that could lead to high memory usage by Node.js process. uploadProgress function at https://github.com/sffc/socketio-file-upload/blob/master/server.js#L382 doesn't properly handle return value of FileStream write function. According to Node documentaion here - https://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback When write function returns false, futher attemts to write data should stop until drain event is emitted. Though data still written, Node buffers all written chunks that could cause issues uploading large files.

r-teplov avatar Jan 14 '20 06:01 r-teplov

Thanks for the report. Ultimately what's happening is that we are attempting to push data into the write stream as it gets sent to us from the socket.io connection. Typically network connections are much slower than file I/O, so my expectation is that the write buffer doesn't usually hit its high water mark. However, it would still be beneficial to properly handle this case.

What made you find this issue? Were you having performance problems and found this via debugging, or are you reporting it as a more theoretical problem?

sffc avatar Feb 10 '20 02:02 sffc

Hi.

I had some non relevant issues while saving files on my local machine. So i checked out source code and stumbled upon code mentioned above. I played with emitChunkFailed prop and it does really emitted error event which meant stream highWaterMark was hit. Same result for staging server.

I have not done any stress test for now so i cant confidently report this to be an issue.

r-teplov avatar Feb 10 '20 23:02 r-teplov