Skip to content

Commit

Permalink
http: remove default 'error' listener on upgrade
Browse files Browse the repository at this point in the history
Remove the default `'error'` listener when the socket is freed. This
is consistent with the client and prevents spurious `'clientError'`
events from being emitted on the server.

PR-URL: nodejs#18868
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
  • Loading branch information
lpinca authored and BridgeAR committed Feb 22, 2018
1 parent d6fc7e3 commit 51be03c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ function onParserExecuteCommon(server, socket, parser, state, ret, d) {
socket.removeListener('close', state.onClose);
socket.removeListener('drain', state.onDrain);
socket.removeListener('drain', ondrain);
socket.removeListener('error', socketOnError);
unconsume(parser, socket);
parser.finish();
freeParser(parser, req, null);
Expand Down
7 changes: 7 additions & 0 deletions test/parallel/test-http-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ server.on('connect', common.mustCall((req, socket, firstBodyChunk) => {
assert.strictEqual(req.method, 'CONNECT');
assert.strictEqual(req.url, 'google.com:443');

// Make sure this socket has detached.
assert.strictEqual(socket.listeners('close').length, 0);
assert.strictEqual(socket.listeners('drain').length, 0);
assert.strictEqual(socket.listeners('data').length, 0);
assert.strictEqual(socket.listeners('end').length, 1);
assert.strictEqual(socket.listeners('error').length, 0);

socket.write('HTTP/1.1 200 Connection established\r\n\r\n');

let data = firstBodyChunk.toString();
Expand Down

0 comments on commit 51be03c

Please sign in to comment.