Skip to content

Commit 1978285

Browse files
ronagruyadorno
authored andcommitted
http: don't emit error after destroy
PR-URL: #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>
1 parent 2beb4f1 commit 1978285

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/_http_outgoing.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,10 @@ OutgoingMessage.prototype.write = function write(chunk, encoding, callback) {
908908
};
909909

910910
function onError(msg, err, callback) {
911+
if (msg.destroyed) {
912+
return;
913+
}
914+
911915
const triggerAsyncId = msg.socket ? msg.socket[async_id_symbol] : undefined;
912916
defaultTriggerAsyncIdScope(triggerAsyncId,
913917
process.nextTick,
@@ -919,7 +923,7 @@ function onError(msg, err, callback) {
919923

920924
function emitErrorNt(msg, err, callback) {
921925
callback(err);
922-
if (typeof msg.emit === 'function' && !msg._closed) {
926+
if (typeof msg.emit === 'function' && !msg.destroyed) {
923927
msg.emit('error', err);
924928
}
925929
}

test/parallel/test-http-outgoing-destroyed.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,27 @@ const assert = require('assert');
5151
.on('error', common.mustCall())
5252
.write('asd');
5353
});
54+
}
5455

56+
{
57+
const server = http.createServer(common.mustCall((req, res) => {
58+
assert.strictEqual(res.closed, false);
59+
res.end();
60+
res.destroy();
61+
// Make sure not to emit 'error' after .destroy().
62+
res.end('asd');
63+
assert.strictEqual(res.errored, undefined);
64+
})).listen(0, () => {
65+
http
66+
.request({
67+
port: server.address().port,
68+
method: 'GET'
69+
})
70+
.on('response', common.mustCall((res) => {
71+
res.resume().on('end', common.mustCall(() => {
72+
server.close();
73+
}));
74+
}))
75+
.end();
76+
});
5577
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy