http: don't destroy completed request

Calling destroy() on a completed ClientRequest, i.e.
once 'close' will be emitted should be a noop. Also
before emitting 'close' destroyed === true.

Fixes: https://github.com/nodejs/node/issues/32851

PR-URL: https://github.com/nodejs/node/pull/33120
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
Robert Nagy 2020-04-28 13:57:32 +02:00
parent 8a6fab02ad
commit b04e88439a
10 changed files with 60 additions and 5 deletions

View file

@ -41,6 +41,7 @@ server.listen(0, options.host, function() {
// This space intentionally left blank
});
req.on('close', function() {
assert.strictEqual(req.destroyed, true);
server.close();
});
function destroy() {