Skip to content
Closed
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
stream: fix multiple Writable.destroy() calls
Calling Writable.destroy() multiple times in the same tick
could cause an assertion error.

Fixes: #38189

PR-URL: #38221
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Nitzan Uziely <linkgoron@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Backport-PR-URL: #38473
  • Loading branch information
ronag committed Apr 29, 2021
commit e516c0a67fc8de054f8b44d539739ffac193e239
1 change: 1 addition & 0 deletions lib/internal/streams/writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ ObjectDefineProperties(Writable.prototype, {
const destroy = destroyImpl.destroy;
Writable.prototype.destroy = function(err, cb) {
const state = this._writableState;

if (!state.destroyed) {
process.nextTick(errorBuffer, state, new ERR_STREAM_DESTROYED('write'));
}
Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-stream-writable-destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,3 +417,14 @@ const assert = require('assert');
}));
write.write('asd');
}

{
// Destroy twice
const write = new Writable({
write(chunk, enc, cb) { cb(); }
});

write.end(common.mustCall());
write.destroy();
write.destroy();
}