Skip to content

Commit

Permalink
Destroy file stream in case of upload timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanBurunkov committed Apr 8, 2020
1 parent 5fb6150 commit 055ceac
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/processMultipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ module.exports = (options, req, res, next) => {
: memHandler(options, field, filename); // Upload into RAM.
// Define upload timer.
const uploadTimer = new UploadTimer(options.uploadTimeout, () => {
debugLog(options, `Upload timeout ${field}->${filename}, bytes:${getFileSize()}`);
cleanup();
// After destroy an error event will be emitted and file clean up will be done.
file.destroy(new Error(`Upload timeout ${field}->${filename}, bytes:${getFileSize()}`));
});

file.on('limit', () => {
Expand Down Expand Up @@ -109,9 +109,8 @@ module.exports = (options, req, res, next) => {
});

file.on('error', (err) => {
// Reset upload timer in case of errors.
uploadTimer.clear();
debugLog(options, `Error ${field}->${filename}, bytes:${getFileSize()}, error:${err}`);
uploadTimer.clear(); // Reset upload timer in case of errors.
debugLog(options, err);
cleanup();
next();
});
Expand Down

0 comments on commit 055ceac

Please sign in to comment.