diff --git a/lib/_http_server.js b/lib/_http_server.js index 1d093bab8bdf33..e83eeae85856e1 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -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); diff --git a/test/parallel/test-http-connect.js b/test/parallel/test-http-connect.js index b019c61573e3fa..105c69ce900b22 100644 --- a/test/parallel/test-http-connect.js +++ b/test/parallel/test-http-connect.js @@ -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();