Skip to content

Commit

Permalink
stream: fix multiple Writable.destroy() calls.
Browse files Browse the repository at this point in the history
Calling Writable.destroy() multiple times in the same tick
could cause an assertion error.

Fixes: nodejs#38189
  • Loading branch information
ronag committed Apr 12, 2021
1 parent 30fe4ed commit 6ae4e4a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/internal/streams/writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -855,10 +855,10 @@ Writable.prototype.destroy = function(err, cb) {

// Invoke pending callbacks.
if (
!state.destroyed && (
state.bufferedIndex < state.buffered.length ||
state[kOnFinished].length
) {
assert(!state.destroyed);
)) {
process.nextTick(errorBuffer, state);
}

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 @@ -460,3 +460,14 @@ const assert = require('assert');
assert.strictEqual(write.destroyed, true);
}));
}

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

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

0 comments on commit 6ae4e4a

Please sign in to comment.