Skip to content

Commit

Permalink
http: remove default 'drain' listener on upgrade
Browse files Browse the repository at this point in the history
Ensure that the default `'drain'` listener is removed before the
`'connect'` or `'upgrade'` event is emitted.

PR-URL: nodejs#18866
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
lpinca authored and addaleax committed Feb 26, 2018
1 parent 8773c10 commit 4bce02a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -456,6 +456,7 @@ function socketOnData(d) {

socket.removeListener('data', socketOnData);
socket.removeListener('end', socketOnEnd);
socket.removeListener('drain', ondrain);
parser.finish();
freeParser(parser, req, socket);

Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-http-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,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
Expand Down

0 comments on commit 4bce02a

Please sign in to comment.