From c45d16beaf395d771f5f20e8e0baadbb3ade9d46 Mon Sep 17 00:00:00 2001 From: David Halls Date: Sun, 16 Oct 2022 11:42:25 +0100 Subject: [PATCH] stream: don't push null from closed promise #42694 closed promise is subscribed to first so will be resolved first, before any read promise. This causes data after EOF error to be thrown. Remove the push null from the closed promise handler. The push null gets done from the read handler when it detects done. --- lib/internal/webstreams/adapters.js | 5 ---- ...st-readable-from-web-enqueue-then-close.js | 26 +++++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 test/parallel/test-readable-from-web-enqueue-then-close.js diff --git a/lib/internal/webstreams/adapters.js b/lib/internal/webstreams/adapters.js index 0c5cbc5ea1db9d..5768c71d21ff58 100644 --- a/lib/internal/webstreams/adapters.js +++ b/lib/internal/webstreams/adapters.js @@ -32,7 +32,6 @@ const { const { isDestroyed, isReadable, - isReadableEnded, isWritable, isWritableEnded, } = require('internal/streams/utils'); @@ -528,8 +527,6 @@ function newStreamReadableFromReadableStream(readableStream, options = kEmptyObj reader.closed, () => { closed = true; - if (!isReadableEnded(readable)) - readable.push(null); }, (error) => { closed = true; @@ -794,8 +791,6 @@ function newStreamDuplexFromReadableWritablePair(pair = kEmptyObject, options = reader.closed, () => { readableClosed = true; - if (!isReadableEnded(duplex)) - duplex.push(null); }, (error) => { writableClosed = true; diff --git a/test/parallel/test-readable-from-web-enqueue-then-close.js b/test/parallel/test-readable-from-web-enqueue-then-close.js new file mode 100644 index 00000000000000..e96df70c9eb9d1 --- /dev/null +++ b/test/parallel/test-readable-from-web-enqueue-then-close.js @@ -0,0 +1,26 @@ +'use strict'; +const { mustCall } = require('../common'); +const { Readable, Duplex } = require('stream'); +const { strictEqual } = require('assert'); + +function start(controller) { + controller.enqueue(new Uint8Array(1)); + controller.close(); +} + +Readable.fromWeb(new ReadableStream({ start })) +.on('data', mustCall((d) => { + strictEqual(d.length, 1); +})) +.on('end', mustCall()) +.resume(); + +Duplex.fromWeb({ + readable: new ReadableStream({ start }), + writable: new WritableStream({ write(chunk) {} }) +}) +.on('data', mustCall((d) => { + strictEqual(d.length, 1); +})) +.on('end', mustCall()) +.resume();