diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index 2180b091b7b2f7..fe8f273a0228d1 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -687,7 +687,6 @@ function endWritable(stream, state, cb) { onFinished(stream, state, cb); } state.ended = true; - stream.writable = false; } function onCorkedFinish(corkReq, state, err) { @@ -741,7 +740,7 @@ ObjectDefineProperties(Writable.prototype, { get() { const w = this._writableState; if (!w) return false; - if (w.writable !== undefined) return w.writable; + if (w.writable !== undefined) return w.writable && !w.ended; return Boolean(!w.destroyed && !w.errored && !w.ending); }, set(val) { diff --git a/test/parallel/test-stream-writable-ended-state.js b/test/parallel/test-stream-writable-ended-state.js index e5fa624c12aed7..2c40c62a9ee9a5 100644 --- a/test/parallel/test-stream-writable-ended-state.js +++ b/test/parallel/test-stream-writable-ended-state.js @@ -9,17 +9,24 @@ const writable = new stream.Writable(); writable._write = (chunk, encoding, cb) => { assert.strictEqual(writable._writableState.ended, false); + assert.strictEqual(writable._writableState.writable, undefined); assert.strictEqual(writable.writableEnded, false); cb(); }; assert.strictEqual(writable._writableState.ended, false); +assert.strictEqual(writable._writableState.writable, undefined); +assert.strictEqual(writable.writable, true); assert.strictEqual(writable.writableEnded, false); writable.end('testing ended state', common.mustCall(() => { assert.strictEqual(writable._writableState.ended, true); + assert.strictEqual(writable._writableState.writable, undefined); + assert.strictEqual(writable.writable, false); assert.strictEqual(writable.writableEnded, true); })); assert.strictEqual(writable._writableState.ended, true); +assert.strictEqual(writable._writableState.writable, undefined); +assert.strictEqual(writable.writable, false); assert.strictEqual(writable.writableEnded, true);