Skip to content

Commit fa4b816

Browse files
committed
stream: fix multiple Writable.destroy() calls
Calling Writable.destroy() multiple times in the same tick could cause an assertion error. Fixes: nodejs#38189 PR-URL: nodejs#38221 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Nitzan Uziely <[email protected]> Reviewed-By: Rich Trott <[email protected]> Backport-PR-URL: nodejs#38473
1 parent 8d4936d commit fa4b816

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/internal/streams/writable.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,8 @@ ObjectDefineProperties(Writable.prototype, {
770770
const destroy = destroyImpl.destroy;
771771
Writable.prototype.destroy = function(err, cb) {
772772
const state = this._writableState;
773+
774+
// Invoke pending callbacks.
773775
if (!state.destroyed) {
774776
process.nextTick(errorBuffer, state, new ERR_STREAM_DESTROYED('write'));
775777
}

test/parallel/test-stream-writable-destroy.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,3 +417,14 @@ const assert = require('assert');
417417
}));
418418
write.write('asd');
419419
}
420+
421+
{
422+
// Destroy twice
423+
const write = new Writable({
424+
write(chunk, enc, cb) { cb(); }
425+
});
426+
427+
write.end(common.mustCall());
428+
write.destroy();
429+
write.destroy();
430+
}

0 commit comments

Comments
 (0)