http: remove default 'error' listener on upgrade

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: https://github.com/nodejs/node/pull/18868
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
pull/18881/merge
Luigi Pinca 2018-02-19 17:54:08 +01:00 committed by Ruben Bridgewater
parent d6fc7e3af4
commit 51be03cd57
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
2 changed files with 8 additions and 0 deletions

View File

@ -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);

View File

@ -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();