Skip to content

Commit 1fc00f0

Browse files
lpincarvagg
authored andcommitted
http: do not rely on the 'agentRemove' event
Do not use the `'agentRemove'` event to null `socket._httpMessage` as that event is public and can be used to not keep a request in the agent. Backport-PR-URL: #20786 PR-URL: #20786Fixes: #20690 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
1 parent ffb72f8 commit 1fc00f0

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

‎lib/_http_agent.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ function installListeners(agent, s, options){
277277
s.removeListener('close',onClose);
278278
s.removeListener('free',onFree);
279279
s.removeListener('agentRemove',onRemove);
280-
s._httpMessage=null;
281280
}
282281
s.on('agentRemove',onRemove);
283282
}

‎lib/_http_client.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ function socketOnData(d){
470470
// TODO(isaacs): Need a way to reset a stream to fresh state
471471
// IE, not flowing, and not explicitly paused.
472472
socket._readableState.flowing=null;
473+
socket._httpMessage=null;
473474

474475
req.emit(eventName,res,socket,bodyHead);
475476
req.emit('close');
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
const{ mustCall }=require('../common');
3+
4+
consthttp=require('http');
5+
const{ strictEqual }=require('assert');
6+
7+
constserver=http.createServer(mustCall((req,res)=>{
8+
res.flushHeaders();
9+
}));
10+
11+
server.listen(0,mustCall(()=>{
12+
constreq=http.get({
13+
port: server.address().port
14+
},mustCall(()=>{
15+
const{ socket }=req;
16+
socket.emit('agentRemove');
17+
strictEqual(socket._httpMessage,req);
18+
socket.destroy();
19+
server.close();
20+
}));
21+
}));

0 commit comments

Comments
(0)