Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1978285

Browse filesBrowse 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
Copy full SHA for 1978285

File tree

Expand file treeCollapse file tree

2 files changed

+27
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+27
-1
lines changed
Open diff view settings
Collapse file

‎lib/_http_outgoing.js‎

Copy file name to clipboardExpand all lines: lib/_http_outgoing.js
+5-1Lines 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
}
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-http-outgoing-destroyed.js
+22Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.