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: #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 MylesBorins committed May 23, 2018
1 parent dd32a7a commit 75e4415
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 @@ -276,7 +276,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 @@ -459,6 +459,7 @@ function socketOnData(d) {
socket.removeListener('close', socketCloseListener);
socket.removeListener('error', socketErrorListener);

socket._httpMessage = null;
socket.readableFlowing = null;

req.emit(eventName, res, socket, bodyHead);
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 75e4415

Please sign in to comment.