Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
stream: null push transform in async_iterator
when the readable side of a transform ends any for await
loop on that transform stream should also complete. This
fix prevents for await loop on a transform stream
from hanging indefinitely.

#28566
  • Loading branch information
David Mark Clements committed Jul 6, 2019
commit 80158ecb60e437880338491d6cd59aa720235c6f
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
24 changes: 23 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,28 @@ async function tests() {
}
}

console.log('readable side of a transform stream pushes null');
{
Comment thread
davidmarkclements marked this conversation as resolved.
const transform = new Transform({
objectMode: true,
transform(chunk, enc, cb) {
Comment thread
davidmarkclements marked this conversation as resolved.
Outdated
cb(null, chunk);
}
});
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);
Comment thread
davidmarkclements marked this conversation as resolved.
}

mustReach();
}

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