Skip to content

Commit

Permalink
fix race condition in error handling: expressjs#1177
Browse files Browse the repository at this point in the history
fix leak: expressjs#1120
  • Loading branch information
didiercolens committed Jan 12, 2024
1 parent aa42bea commit 2c3eec2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 9 additions & 1 deletion lib/make-middleware.js
Expand Up @@ -42,13 +42,20 @@ function makeMiddleware (setup) {
var pendingWrites = new Counter()
var uploadedFiles = []

function requestError(error) {
busboy.destroy(error);
}

function done (err) {
if (isDone) return
isDone = true

req.removeListener('error', requestError)
req.unpipe(busboy)
drainStream(req)
busboy.removeAllListeners()
process.nextTick(function () {
busboy.removeAllListeners()
});

onFinished(req, function () { next(err) })
}
Expand Down Expand Up @@ -174,6 +181,7 @@ function makeMiddleware (setup) {
indicateDone()
})

req.on('error', requestError)
req.pipe(busboy)
}
}
Expand Down
5 changes: 3 additions & 2 deletions package.json
@@ -1,11 +1,12 @@
{
"name": "multer",
"name": "@bdb/multer",
"description": "Middleware for handling `multipart/form-data`.",
"version": "1.4.4",
"contributors": [
"Hage Yaapa <captain@hacksparrow.com> (http://www.hacksparrow.com)",
"Jaret Pfluger <https://github.com/jpfluger>",
"Linus Unnebäck <linus@folkdatorn.se>"
"Linus Unnebäck <linus@folkdatorn.se>",
"Didier Colens <dcolens@cisco.com>"
],
"license": "MIT",
"repository": "expressjs/multer",
Expand Down

0 comments on commit 2c3eec2

Please sign in to comment.