Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
stream: fix multiple Writable.destroy() calls.
Calling Writable.destroy() multiple times in the same tick
could cause an assertion error.

Fixes: #38189
  • Loading branch information
ronag committed Apr 12, 2021
commit 6ae4e4a86814f6dac68e0f603ba26fc41cc9939a
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();
}