Skip to content

Commit d406eb2

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. Fixes: #23857
1 parent 69a8e34 commit d406eb2

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
@@ -458,6 +458,10 @@ function socketOnData(d) {
458458
socket.removeListener('data', socketOnData);
459459
socket.removeListener('end', socketOnEnd);
460460
socket.removeListener('drain', ondrain);
461+
462+
if (req.timeoutCb)
463+
socket.removeListener('timeout', req.timeoutCb);
464+
461465
parser.finish();
462466
freeParser(parser, req, socket);
463467

lib/_http_server.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ function onParserExecuteCommon(server, socket, parser, state, ret, d) {
549549
socket.removeListener('drain', state.onDrain);
550550
socket.removeListener('drain', ondrain);
551551
socket.removeListener('error', socketOnError);
552+
socket.removeListener('timeout', socketOnTimeout);
552553
unconsume(parser, socket);
553554
parser.finish();
554555
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)