From 274b2b4fbaa4e33f490f92947456a9e7d30a2aaa Mon Sep 17 00:00:00 2001 From: UnlimitedBytes Date: Sun, 10 Jul 2022 19:47:48 +0200 Subject: [PATCH 1/2] fix: busboy not closed when request errors One important caveat was ignored by piping request stream to busboy stream. This commit aknowledges that caveat. More information on: https://nodejs.org/api/stream.html#readablepipedestination-options --- lib/make-middleware.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/make-middleware.js b/lib/make-middleware.js index b033cbd9..83eebe3c 100644 --- a/lib/make-middleware.js +++ b/lib/make-middleware.js @@ -42,10 +42,16 @@ function makeMiddleware (setup) { var pendingWrites = new Counter() var uploadedFiles = [] + function requestError(error) { + if(!busboy) return + busboy.destroy(error) + } + function done (err) { if (isDone) return isDone = true + req.removeEventListener('error', requestError) req.unpipe(busboy) drainStream(req) busboy.removeAllListeners() @@ -174,6 +180,7 @@ function makeMiddleware (setup) { indicateDone() }) + req.on('error', requestError) req.pipe(busboy) } } From 6fe29367a9959a248a563fcdaa0d0f5db02a9d8c Mon Sep 17 00:00:00 2001 From: UnlimitedBytes Date: Sat, 16 Jul 2022 04:50:34 +0200 Subject: [PATCH 2/2] fix: change removeEventListener to removeListener As mentioned by @Gerard-Szulc we use `removeListener` in node instead of `removeEventListener` --- lib/make-middleware.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/make-middleware.js b/lib/make-middleware.js index 83eebe3c..529c1928 100644 --- a/lib/make-middleware.js +++ b/lib/make-middleware.js @@ -51,7 +51,7 @@ function makeMiddleware (setup) { if (isDone) return isDone = true - req.removeEventListener('error', requestError) + req.removeListener('error', requestError) req.unpipe(busboy) drainStream(req) busboy.removeAllListeners()