From 2b7f920e26171f05fac437d867a30209f57c6bad Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Mon, 19 Feb 2018 15:09:48 +0100 Subject: [PATCH] http: remove default 'drain' listener on upgrade Ensure that the default `'drain'` listener is removed before the `'connect'` or `'upgrade'` event is emitted. PR-URL: https://github.com/nodejs/node/pull/18866 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater --- lib/_http_client.js | 3 ++- test/parallel/test-http-connect.js | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/_http_client.js b/lib/_http_client.js index cab11ae8f296c0..311da63c5bfe9a 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -37,7 +37,7 @@ const { OutgoingMessage } = require('_http_outgoing'); const Agent = require('_http_agent'); const { Buffer } = require('buffer'); const { urlToOptions, searchParamsSymbol } = require('internal/url'); -const { outHeadersKey } = require('internal/http'); +const { outHeadersKey, ondrain } = require('internal/http'); const { nextTick } = require('internal/process/next_tick'); const errors = require('internal/errors'); @@ -424,6 +424,7 @@ function socketOnData(d) { socket.removeListener('data', socketOnData); socket.removeListener('end', socketOnEnd); + socket.removeListener('drain', ondrain); parser.finish(); freeParser(parser, req, socket); diff --git a/test/parallel/test-http-connect.js b/test/parallel/test-http-connect.js index e7fb116de93267..f90d235521a649 100644 --- a/test/parallel/test-http-connect.js +++ b/test/parallel/test-http-connect.js @@ -74,6 +74,7 @@ server.listen(0, common.mustCall(() => { assert.strictEqual(socket._httpMessage, null); assert.strictEqual(socket.listeners('connect').length, 0); assert.strictEqual(socket.listeners('data').length, 0); + assert.strictEqual(socket.listeners('drain').length, 0); // the stream.Duplex onend listener // allow 0 here, so that i can run the same test on streams1 impl