Skip to content

Commit 3c05b03

Browse files
lpincaMylesBorins
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. PR-URL: #20786 Fixes: #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 275907f commit 3c05b03

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

lib/_http_agent.js

-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ function installListeners(agent, s, options) {
276276
s.removeListener('close', onClose);
277277
s.removeListener('free', onFree);
278278
s.removeListener('agentRemove', onRemove);
279-
s._httpMessage = null;
280279
}
281280
s.on('agentRemove', onRemove);
282281
}

lib/_http_client.js

+1
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ function socketOnData(d) {
459459
socket.removeListener('close', socketCloseListener);
460460
socket.removeListener('error', socketErrorListener);
461461

462+
socket._httpMessage = null;
462463
socket.readableFlowing = null;
463464

464465
req.emit(eventName, res, socket, bodyHead);
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
const { mustCall } = require('../common');
3+
4+
const http = require('http');
5+
const { strictEqual } = require('assert');
6+
7+
const server = http.createServer(mustCall((req, res) => {
8+
res.flushHeaders();
9+
}));
10+
11+
server.listen(0, mustCall(() => {
12+
const req = 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)