Skip to content

Commit 2c3eec2

Browse files
committed
fix race condition in error handling: expressjs#1177
fix leak: expressjs#1120
1 parent aa42bea commit 2c3eec2

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/make-middleware.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,20 @@ function makeMiddleware (setup) {
4242
var pendingWrites = new Counter()
4343
var uploadedFiles = []
4444

45+
function requestError(error) {
46+
busboy.destroy(error);
47+
}
48+
4549
function done (err) {
4650
if (isDone) return
4751
isDone = true
4852

53+
req.removeListener('error', requestError)
4954
req.unpipe(busboy)
5055
drainStream(req)
51-
busboy.removeAllListeners()
56+
process.nextTick(function () {
57+
busboy.removeAllListeners()
58+
});
5259

5360
onFinished(req, function () { next(err) })
5461
}
@@ -174,6 +181,7 @@ function makeMiddleware (setup) {
174181
indicateDone()
175182
})
176183

184+
req.on('error', requestError)
177185
req.pipe(busboy)
178186
}
179187
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
2-
"name": "multer",
2+
"name": "@bdb/multer",
33
"description": "Middleware for handling `multipart/form-data`.",
44
"version": "1.4.4",
55
"contributors": [
66
"Hage Yaapa <[email protected]> (http://www.hacksparrow.com)",
77
"Jaret Pfluger <https://github.com/jpfluger>",
8-
"Linus Unnebäck <[email protected]>"
8+
"Linus Unnebäck <[email protected]>",
9+
"Didier Colens <[email protected]>"
910
],
1011
"license": "MIT",
1112
"repository": "expressjs/multer",

0 commit comments

Comments
 (0)