Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion lib/internal/streams/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ async function* createAsyncIterator(stream, options) {
stream.on('readable', next);

let error;
eos(stream, { writable: false }, (err) => {
const cleanup = eos(stream, { writable: false }, (err) => {
error = err ? aggregateTwoErrors(error, err) : null;
callback();
callback = nop;
Expand Down Expand Up @@ -1150,6 +1150,9 @@ async function* createAsyncIterator(stream, options) {
(error === undefined || stream._readableState.autoDestroy)
) {
destroyImpl.destroyer(stream, null);
} else {
stream.off('readable', next);
cleanup();
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions test/parallel/test-stream-readable-async-iterators.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,20 @@ async function tests() {
}
);
}

// Check for dangling listeners
(async function() {
const readable = createReadable();
const opts = { destroyOnReturn: false };
while (readable.readable) {
// eslint-disable-next-line no-unused-vars
for await (const chunk of readable.iterator(opts)) {
break;
}
}

assert.deepStrictEqual(readable.eventNames(), []);
})().then(common.mustCall());
}

{
Expand Down