Skip to content

Commit dbb0d26

Browse files
ronagtargos
authored andcommitted
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
1 parent 5995221 commit dbb0d26

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/internal/streams/writable.js

+1
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,7 @@ ObjectDefineProperties(Writable.prototype, {
778778
const destroy = destroyImpl.destroy;
779779
Writable.prototype.destroy = function(err, cb) {
780780
const state = this._writableState;
781+
781782
if (!state.destroyed) {
782783
process.nextTick(errorBuffer, state, new ERR_STREAM_DESTROYED('write'));
783784
}

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

+11
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)