Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

streams: handle null push for transform in async_iterator #28566

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/internal/streams/async_iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ const createReadableStreamAsyncIterator = (stream) => {
});
iterator[kLastPromise] = null;

finished(stream, (err) => {
finished(stream, { writable: false }, (err) => {
if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') {
const reject = iterator[kLastReject];
// Reject if we are waiting for data in the Promise returned by next() and
Expand Down
22 changes: 21 additions & 1 deletion test/parallel/test-stream-readable-async-iterators.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const common = require('../common');
const { Readable, PassThrough, pipeline } = require('stream');
const { Readable, Transform, PassThrough, pipeline } = require('stream');
const assert = require('assert');

async function tests() {
Expand Down Expand Up @@ -396,6 +396,26 @@ async function tests() {
}
}

console.log('readable side of a transform stream pushes null');
{
davidmarkclements marked this conversation as resolved.
Show resolved Hide resolved
const transform = new Transform({
objectMode: true,
transform: common.mustNotCall()
});
transform.push(0);
transform.push(1);
transform.push(null);
const mustReach = common.mustCall();
const iter = transform[Symbol.asyncIterator]();
assert.strictEqual((await iter.next()).value, 0);

for await (const d of iter) {
assert.strictEqual(d, 1);
davidmarkclements marked this conversation as resolved.
Show resolved Hide resolved
}

mustReach();
}

{
console.log('all next promises must be resolved on end');
const r = new Readable({
Expand Down