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: https://github.com/nodejs/node/pull/20786
Fixes: https://github.com/nodejs/node/issues/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>
This commit is contained in:
Luigi Pinca 2018-05-16 22:15:20 +02:00 committed by Anatoli Papirovski
parent ef9d0ae6f2
commit 4a940aadfa
No known key found for this signature in database
GPG Key ID: 614E2E1ABEB4B2C0
3 changed files with 22 additions and 1 deletions

View File

@ -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);
}

View File

@ -467,6 +467,7 @@ function socketOnData(d) {
socket.removeListener('close', socketCloseListener);
socket.removeListener('error', socketErrorListener);
socket._httpMessage = null;
socket.readableFlowing = null;
req.emit(eventName, res, socket, bodyHead);

View File

@ -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();
}));
}));