0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 13:09:21 +01:00

http: don't emit error after destroy

PR-URL: https://github.com/nodejs/node/pull/55457
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
This commit is contained in:
Robert Nagy 2024-10-28 13:57:58 +01:00 committed by GitHub
parent 7cb3a662da
commit 5633c62219
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 2 deletions

View File

@ -908,6 +908,10 @@ OutgoingMessage.prototype.write = function write(chunk, encoding, callback) {
};
function onError(msg, err, callback) {
if (msg.destroyed) {
return;
}
const triggerAsyncId = msg.socket ? msg.socket[async_id_symbol] : undefined;
defaultTriggerAsyncIdScope(triggerAsyncId,
process.nextTick,
@ -919,7 +923,7 @@ function onError(msg, err, callback) {
function emitErrorNt(msg, err, callback) {
callback(err);
if (typeof msg.emit === 'function' && !msg._closed) {
if (typeof msg.emit === 'function' && !msg.destroyed) {
msg.emit('error', err);
}
}

View File

@ -51,5 +51,27 @@ const assert = require('assert');
.on('error', common.mustCall())
.write('asd');
});
}
{
const server = http.createServer(common.mustCall((req, res) => {
assert.strictEqual(res.closed, false);
res.end();
res.destroy();
// Make sure not to emit 'error' after .destroy().
res.end('asd');
assert.strictEqual(res.errored, undefined);
})).listen(0, () => {
http
.request({
port: server.address().port,
method: 'GET'
})
.on('response', common.mustCall((res) => {
res.resume().on('end', common.mustCall(() => {
server.close();
}));
}))
.end();
});
}