From 93fb54a55b2ead73a95ff9293eb099903a46e49c Mon Sep 17 00:00:00 2001 From: Chetan Karande Date: Sat, 21 Sep 2019 10:12:13 -0400 Subject: [PATCH 1/2] stream: cleanup use of internal ended state --- lib/internal/http2/compat.js | 2 +- lib/internal/worker.js | 4 ++-- lib/net.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js index 9cf19250a8a3b0..2d6ed47d74e29f 100644 --- a/lib/internal/http2/compat.js +++ b/lib/internal/http2/compat.js @@ -303,7 +303,7 @@ class Http2ServerRequest extends Readable { get complete() { return this[kAborted] || - this._readableState.ended || + this.readableEnded || this[kState].closed || this[kStream].destroyed; } diff --git a/lib/internal/worker.js b/lib/internal/worker.js index df0646ff4f68b8..fc6588d527d12b 100644 --- a/lib/internal/worker.js +++ b/lib/internal/worker.js @@ -207,11 +207,11 @@ class Worker extends EventEmitter { const { stdout, stderr } = this[kParentSideStdio]; - if (!stdout._readableState.ended) { + if (!stdout.readableEnded) { debug(`[${threadId}] explicitly closes stdout for ${this.threadId}`); stdout.push(null); } - if (!stderr._readableState.ended) { + if (!stderr.readableEnded) { debug(`[${threadId}] explicitly closes stderr for ${this.threadId}`); stderr.push(null); } diff --git a/lib/net.js b/lib/net.js index 1eb1d212cddbb3..760bf084f4d324 100644 --- a/lib/net.js +++ b/lib/net.js @@ -422,7 +422,7 @@ function afterShutdown(status) { if (self.destroyed) return; - if (!self.readable || self._readableState.ended) { + if (!self.readable || self.readableEnded) { debug('readableState ended, destroying'); self.destroy(); } From dacc2415c6880c36673b35352d9d6b0230c02fa6 Mon Sep 17 00:00:00 2001 From: Chetan Karande Date: Sat, 21 Sep 2019 15:20:56 -0400 Subject: [PATCH 2/2] stream: add test for multiple .push(null) --- test/parallel/test-stream-readable-ended.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/parallel/test-stream-readable-ended.js b/test/parallel/test-stream-readable-ended.js index a224c68f041d10..f504330cb165fc 100644 --- a/test/parallel/test-stream-readable-ended.js +++ b/test/parallel/test-stream-readable-ended.js @@ -31,3 +31,16 @@ const assert = require('assert'); assert.strictEqual(readable.readableEnded, false); })); } + +// Verifies no `error` triggered on multiple .push(null) invocations +{ + const readable = new Readable(); + + readable.on('readable', () => { readable.read(); }); + readable.on('error', common.mustNotCall()); + readable.on('end', common.mustCall()); + + readable.push('a'); + readable.push(null); + readable.push(null); +}