richardgirges / express-fileupload

Simple express file upload middleware that wraps around busboy
MIT License
1.52k stars 261 forks source link

when file.on('data') event timeouts, the case isn't handled properly. #202

Closed zzxoto closed 4 years ago

zzxoto commented 4 years ago

Steps to reproduce.

use following options

{
  debug: true, 
  uploadTimeout: 0,
  useTempFiles: true
}

Following error is logged:

...(some other logs/errors i have omitted)...
UnhandledPromiseRejectionWarning: Error [ERR_STREAM_WRITE_AFTER_END]: write after end
...(some other logs/errors I have omitted)...
Error write temp file error:Error [ERR_STREAM_WRITE_AFTER_END]: write after end
Uploading sampleFile->Hallelujah_chorus.wma, bytes:114529...
Error write temp file error:Error [ERR_STREAM_WRITE_AFTER_END]: write after end

What i gather is that temp file gets closed in a timeout, and upon next data event, trying to write on previously closed temp file creates this crash.

RomanBurunkov commented 4 years ago

Have added a checks to not start a timer in case of zero uploadTimeout.

'[ERR_STREAM_WRITE_AFTER_END]: write after end' it is the same as #192.