Skip to content

Commit ce54af2

Browse files
committed
http: preserve destroy error in _writeRaw callback
1 parent 7c6b543 commit ce54af2

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

lib/_http_outgoing.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ function _writeRaw(data, encoding, callback, size) {
377377

378378
if (this.destroyed) {
379379
if (typeof callback === 'function') {
380-
process.nextTick(callback, new ERR_STREAM_DESTROYED('write'));
380+
process.nextTick(callback, this.errored ?? new ERR_STREAM_DESTROYED('write'));
381381
}
382382
return false;
383383
}
@@ -387,7 +387,7 @@ function _writeRaw(data, encoding, callback, size) {
387387
// The socket was destroyed. If we're still trying to write to it,
388388
// then we haven't gotten the 'close' event yet.
389389
if (typeof callback === 'function') {
390-
process.nextTick(callback, new ERR_STREAM_DESTROYED('write'));
390+
process.nextTick(callback, this.errored ?? new ERR_STREAM_DESTROYED('write'));
391391
}
392392
return false;
393393
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ const OutgoingMessage = http.OutgoingMessage;
2626
msg.on('error', common.mustNotCall());
2727
}
2828

29+
{
30+
const msg = new OutgoingMessage();
31+
const destroyError = new Error('destroyed');
32+
msg.destroy(destroyError);
33+
34+
assert.strictEqual(msg._writeRaw('asd', common.mustCall((err) => {
35+
assert.strictEqual(err, destroyError);
36+
})), false);
37+
msg.on('error', common.mustNotCall());
38+
}
39+
2940
{
3041
const msg = new OutgoingMessage();
3142
msg.socket = { destroyed: true };

0 commit comments

Comments
 (0)