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.

Backport-PR-URL: #20786
PR-URL: #20786
Fixes: #20690
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
  • Loading branch information
lpinca authored and rvagg committed Aug 16, 2018
1 parent ffb72f8 commit 1fc00f0
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 1fc00f0

Please sign in to comment.