Skip to content

Commit d5577f0

Browse files
committed
http: remove default 'timeout' listener on upgrade
Remove the default listener of the `'timeout'` event from the socket before emitting the `'connect'` or `'upgrade'` event. PR-URL: #26030 Fixes: #23857 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent a18e27d commit d5577f0

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

lib/_http_client.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,10 @@ function socketOnData(d) {
465465
socket.removeListener('data', socketOnData);
466466
socket.removeListener('end', socketOnEnd);
467467
socket.removeListener('drain', ondrain);
468+
469+
if (req.timeoutCb)
470+
socket.removeListener('timeout', req.timeoutCb);
471+
468472
parser.finish();
469473
freeParser(parser, req, socket);
470474

lib/_http_server.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ function onParserExecuteCommon(server, socket, parser, state, ret, d) {
568568
socket.removeListener('drain', state.onDrain);
569569
socket.removeListener('drain', ondrain);
570570
socket.removeListener('error', socketOnError);
571+
socket.removeListener('timeout', socketOnTimeout);
571572
unconsume(parser, socket);
572573
parser.finish();
573574
freeParser(parser, req, socket);

test/parallel/test-http-connect.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ server.on('connect', common.mustCall((req, socket, firstBodyChunk) => {
3636
assert.strictEqual(socket.listenerCount('data'), 0);
3737
assert.strictEqual(socket.listenerCount('end'), 1);
3838
assert.strictEqual(socket.listenerCount('error'), 0);
39+
assert.strictEqual(socket.listenerCount('timeout'), 0);
3940

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

@@ -53,7 +54,8 @@ server.listen(0, common.mustCall(() => {
5354
const req = http.request({
5455
port: server.address().port,
5556
method: 'CONNECT',
56-
path: 'google.com:443'
57+
path: 'google.com:443',
58+
timeout: 20000
5759
}, common.mustNotCall());
5860

5961
req.on('socket', common.mustCall((socket) => {
@@ -80,6 +82,7 @@ server.listen(0, common.mustCall(() => {
8082
assert.strictEqual(socket.listenerCount('close'), 0);
8183
assert.strictEqual(socket.listenerCount('error'), 0);
8284
assert.strictEqual(socket.listenerCount('agentRemove'), 0);
85+
assert.strictEqual(socket.listenerCount('timeout'), 0);
8386

8487
let data = firstBodyChunk.toString();
8588
socket.on('data', (buf) => {

0 commit comments

Comments
 (0)