Skip to content

Commit 055ceac

Browse files
committedApr 8, 2020
Destroy file stream in case of upload timeout.
1 parent 5fb6150 commit 055ceac

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed
 

‎lib/processMultipart.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ module.exports = (options, req, res, next) => {
5959
: memHandler(options, field, filename); // Upload into RAM.
6060
// Define upload timer.
6161
const uploadTimer = new UploadTimer(options.uploadTimeout, () => {
62-
debugLog(options, `Upload timeout ${field}->${filename}, bytes:${getFileSize()}`);
63-
cleanup();
62+
// After destroy an error event will be emitted and file clean up will be done.
63+
file.destroy(new Error(`Upload timeout ${field}->${filename}, bytes:${getFileSize()}`));
6464
});
6565

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

111111
file.on('error', (err) => {
112-
// Reset upload timer in case of errors.
113-
uploadTimer.clear();
114-
debugLog(options, `Error ${field}->${filename}, bytes:${getFileSize()}, error:${err}`);
112+
uploadTimer.clear(); // Reset upload timer in case of errors.
113+
debugLog(options, err);
115114
cleanup();
116115
next();
117116
});

0 commit comments

Comments
 (0)
Please sign in to comment.