From 36318ae4c1fee02d3bc3737e34e1ea33e604f674 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(); }