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 674b932

Browse filesBrowse files
ronagmarco-ippolito
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 e87db6c commit 674b932
Copy full SHA for 674b932

File tree

Expand file treeCollapse file tree

2 files changed

+27
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+27
-1
lines changed

‎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
@@ -864,6 +864,10 @@ OutgoingMessage.prototype.write = function write(chunk, encoding, callback) {
864864
};
865865

866866
function onError(msg, err, callback) {
867+
if (msg.destroyed) {
868+
return;
869+
}
870+
867871
const triggerAsyncId = msg.socket ? msg.socket[async_id_symbol] : undefined;
868872
defaultTriggerAsyncIdScope(triggerAsyncId,
869873
process.nextTick,
@@ -875,7 +879,7 @@ function onError(msg, err, callback) {
875879

876880
function emitErrorNt(msg, err, callback) {
877881
callback(err);
878-
if (typeof msg.emit === 'function' && !msg._closed) {
882+
if (typeof msg.emit === 'function' && !msg.destroyed) {
879883
msg.emit('error', err);
880884
}
881885
}

‎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.