From e183e5d87435f73baa83024e937a0bcddf807757 Mon Sep 17 00:00:00 2001 From: Mary Marchini Date: Tue, 28 Sep 2021 20:42:36 -0700 Subject: [PATCH] fix: use more reliable close event The close event from the request object is not guaranteed to fire on the same order across major versions of Node.js, the more accurate way to look if the connection was closed is to listen to the event on the socket. Fixes tests on v16. Ref: https://github.com/nodejs/node/issues/38924 --- lib/plugins/bodyReader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/bodyReader.js b/lib/plugins/bodyReader.js index a71cfb0be..82c9d1016 100644 --- a/lib/plugins/bodyReader.js +++ b/lib/plugins/bodyReader.js @@ -186,7 +186,7 @@ function bodyReader(options) { // add 'close and 'aborted' event handlers so that requests (and their // corresponding memory) don't leak if client stops sending data half // way through a POST request - req.once('close', next); + req.socket.once('close', next); req.once('aborted', next); req.resume(); }