From 16b23ae0f8bfedd2d35ab768a125f706c85e4c50 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Tue, 8 Oct 2019 22:00:55 +0200 Subject: [PATCH] stream: no writable finish after destroy --- lib/_stream_writable.js | 1 + test/parallel/test-stream-duplex-destroy.js | 2 -- test/parallel/test-stream-transform-destroy.js | 2 -- test/parallel/test-stream-writable-destroy.js | 2 -- test/parallel/test-stream-write-destroy.js | 6 ++---- 5 files changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index 9b75b672cbd843..192c35b11ca02a 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -626,6 +626,7 @@ Object.defineProperty(Writable.prototype, 'writableLength', { function needFinish(state) { return (state.ending && + !state.destroyed && state.length === 0 && !state.errored && state.bufferedRequest === null && diff --git a/test/parallel/test-stream-duplex-destroy.js b/test/parallel/test-stream-duplex-destroy.js index 3c38d2c364051c..cbccd4428a3c0c 100644 --- a/test/parallel/test-stream-duplex-destroy.js +++ b/test/parallel/test-stream-duplex-destroy.js @@ -123,9 +123,7 @@ const assert = require('assert'); duplex.destroy(); duplex.removeListener('end', fail); - duplex.removeListener('finish', fail); duplex.on('end', common.mustCall()); - duplex.on('finish', common.mustCall()); assert.strictEqual(duplex.destroyed, true); } diff --git a/test/parallel/test-stream-transform-destroy.js b/test/parallel/test-stream-transform-destroy.js index c594d9989ae4de..20cd31a37ea097 100644 --- a/test/parallel/test-stream-transform-destroy.js +++ b/test/parallel/test-stream-transform-destroy.js @@ -115,9 +115,7 @@ const assert = require('assert'); transform.destroy(); transform.removeListener('end', fail); - transform.removeListener('finish', fail); transform.on('end', common.mustCall()); - transform.on('finish', common.mustCall()); } { diff --git a/test/parallel/test-stream-writable-destroy.js b/test/parallel/test-stream-writable-destroy.js index c4a96788ab24dd..fb964b05f0d1e8 100644 --- a/test/parallel/test-stream-writable-destroy.js +++ b/test/parallel/test-stream-writable-destroy.js @@ -124,8 +124,6 @@ const assert = require('assert'); write.destroy(); - write.removeListener('finish', fail); - write.on('finish', common.mustCall()); assert.strictEqual(write.destroyed, true); } diff --git a/test/parallel/test-stream-write-destroy.js b/test/parallel/test-stream-write-destroy.js index 297217eb4accc6..9d05643553959a 100644 --- a/test/parallel/test-stream-write-destroy.js +++ b/test/parallel/test-stream-write-destroy.js @@ -57,12 +57,10 @@ for (const withPendingData of [ false, true ]) { w.destroy(); assert.strictEqual(chunksWritten, 1); callbacks.shift()(); - assert.strictEqual(chunksWritten, 2); + assert.strictEqual(chunksWritten, useEnd && !withPendingData ? 1 : 2); assert.strictEqual(callbacks.length, 0); assert.strictEqual(drains, 1); - // When we used `.end()`, we see the 'finished' event if and only if - // we actually finished processing the write queue. - assert.strictEqual(finished, !withPendingData && useEnd); + assert.strictEqual(finished, false); } }