Skip to content

Commit

Permalink
http: do not rely on the 'agentRemove' event
Browse files Browse the repository at this point in the history
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: nodejs/node#20786
Fixes: nodejs/node#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]>
  • Loading branch information
lpinca committed Jul 10, 2018
1 parent a6299d6 commit 11333c2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ function installListeners(agent, s, options) {
s.removeListener('close', onClose);
s.removeListener('free', onFree);
s.removeListener('agentRemove', onRemove);
s._httpMessage = null;
}
s.on('agentRemove', onRemove);
}
Expand Down
1 change: 1 addition & 0 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ function socketOnData(d) {
// TODO(isaacs): Need a way to reset a stream to fresh state
// IE, not flowing, and not explicitly paused.
socket._readableState.flowing = null;
socket._httpMessage = null;

req.emit(eventName, res, socket, bodyHead);
req.emit('close');
Expand Down
21 changes: 21 additions & 0 deletions test/parallel/test-http-agent-remove.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';
const { mustCall } = require('../common');

const http = require('http');
const { strictEqual } = require('assert');

const server = http.createServer(mustCall((req, res) => {
res.flushHeaders();
}));

server.listen(0, mustCall(() => {
const req = http.get({
port: server.address().port
}, mustCall(() => {
const { socket } = req;
socket.emit('agentRemove');
strictEqual(socket._httpMessage, req);
socket.destroy();
server.close();
}));
}));

0 comments on commit 11333c2

Please sign in to comment.