Skip to content

Commit ced7f67

Browse files
timdpMylesBorins
authored andcommitted
http: make ClientRequest#setTimeout() noop at end
Originally discovered and resolved by @szmarczak. PR-URL: #25536Fixes: #25499 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent f8800c9 commit ced7f67

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

‎lib/_http_client.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,10 @@ function _deferToConnect(method, arguments_, cb){
727727
}
728728

729729
ClientRequest.prototype.setTimeout=functionsetTimeout(msecs,callback){
730+
if(this._ended){
731+
returnthis;
732+
}
733+
730734
listenSocketTimeout(this);
731735
msecs=validateTimerDuration(msecs);
732736
if(callback)this.once('timeout',callback);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
// Test https://github.com/nodejs/node/issues/25499 fix.
4+
5+
const{ mustCall }=require('../common');
6+
7+
const{ Agent, createServer, get }=require('http');
8+
const{ strictEqual }=require('assert');
9+
10+
constserver=createServer(mustCall((req,res)=>{
11+
res.end();
12+
}));
13+
14+
server.listen(0,()=>{
15+
constagent=newAgent({keepAlive: true,maxSockets: 1});
16+
constport=server.address().port;
17+
18+
letsocket;
19+
20+
constreq=get({ agent, port },(res)=>{
21+
res.on('end',()=>{
22+
strictEqual(req.setTimeout(0),req);
23+
strictEqual(socket.listenerCount('timeout'),0);
24+
agent.destroy();
25+
server.close();
26+
});
27+
res.resume();
28+
});
29+
30+
req.on('socket',(sock)=>{
31+
socket=sock;
32+
});
33+
});

0 commit comments

Comments
(0)