node/test/parallel/test-http-client-agent-abort-close-event.js
Robert Nagy b04e88439a 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>
2020-05-11 18:02:32 +02:00

26 lines
623 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
const server = http.createServer(common.mustNotCall());
const keepAliveAgent = new http.Agent({ keepAlive: true });
server.listen(0, common.mustCall(() => {
const req = http.get({
port: server.address().port,
agent: keepAliveAgent
});
req
.on('socket', common.mustNotCall())
.on('response', common.mustNotCall())
.on('close', common.mustCall(() => {
assert.strictEqual(req.destroyed, true);
server.close();
keepAliveAgent.destroy();
}))
.abort();
}));