Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,10 @@ OutgoingMessage.prototype.write = function write(chunk, encoding, callback) {
};

function onError(msg, err, callback) {
if (msg.destroyed) {
return;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that if I call end(chunk, CB) and this is both finished and destroyed, the callback won't be called?

}

const triggerAsyncId = msg.socket ? msg.socket[async_id_symbol] : undefined;
defaultTriggerAsyncIdScope(triggerAsyncId,
process.nextTick,
Expand All @@ -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);
}
}
Expand Down
22 changes: 22 additions & 0 deletions test/parallel/test-http-outgoing-destroyed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
Loading