diff --git a/lib/internal/streams/writable.js b/lib/internal/streams/writable.js index e6cfa0dc6629af..421836f34414d7 100644 --- a/lib/internal/streams/writable.js +++ b/lib/internal/streams/writable.js @@ -778,6 +778,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')); } diff --git a/test/parallel/test-stream-writable-destroy.js b/test/parallel/test-stream-writable-destroy.js index 9f6136923ee176..f3ca402d5b3f94 100644 --- a/test/parallel/test-stream-writable-destroy.js +++ b/test/parallel/test-stream-writable-destroy.js @@ -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(); +}