diff --git a/lib/internal/streams/duplex.js b/lib/internal/streams/duplex.js index 35f6ff4b199de1..6892150c49f659 100644 --- a/lib/internal/streams/duplex.js +++ b/lib/internal/streams/duplex.js @@ -59,6 +59,9 @@ ObjectSetPrototypeOf(Duplex, Readable); } } +// Use the `destroy` method of `Writable`. +Duplex.prototype.destroy = Writable.prototype.destroy; + function Duplex(options) { if (!(this instanceof Duplex)) return new Duplex(options); diff --git a/test/parallel/test-stream-duplex-destroy.js b/test/parallel/test-stream-duplex-destroy.js index ea6f6d42c90305..9258cacd0d6f69 100644 --- a/test/parallel/test-stream-duplex-destroy.js +++ b/test/parallel/test-stream-duplex-destroy.js @@ -238,6 +238,7 @@ const assert = require('assert'); }); duplex.on('close', common.mustCall()); } + { // Check abort signal const controller = new AbortController(); @@ -255,3 +256,16 @@ const assert = require('assert'); duplex.on('close', common.mustCall()); controller.abort(); } + +{ + const duplex = new Duplex({ + read() {}, + write(chunk, enc, cb) { cb(); } + }); + + duplex.cork(); + duplex.write('foo', common.mustCall((err) => { + assert.strictEqual(err.code, 'ERR_STREAM_DESTROYED'); + })); + duplex.destroy(); +}