Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7bbc072

Browse filesBrowse files
mcollinatargos
authored andcommitted
stream: do not error async iterators on destroy(null)
Fixes: #23890 PR-URL: #23901 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 5ce3b6d commit 7bbc072
Copy full SHA for 7bbc072

File tree

Expand file treeCollapse file tree

2 files changed

+19
-6
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+19
-6
lines changed
Open diff view settings
Collapse file

‎lib/internal/streams/async_iterator.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/async_iterator.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ const createReadableStreamAsyncIterator = (stream) => {
153153
});
154154

155155
finished(stream, (err) => {
156-
if (err) {
156+
if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') {
157157
const reject = iterator[kLastReject];
158158
// reject if we are waiting for data in the Promise
159159
// returned by next() and store the error
Collapse file

‎test/parallel/test-stream-readable-async-iterators.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-stream-readable-async-iterators.js
+18-5Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,8 @@ async function tests() {
335335

336336
readable.destroy();
337337

338-
try {
339-
await readable[Symbol.asyncIterator]().next();
340-
} catch (e) {
341-
assert.strictEqual(e.code, 'ERR_STREAM_PREMATURE_CLOSE');
342-
}
338+
const { done } = await readable[Symbol.asyncIterator]().next();
339+
assert.strictEqual(done, true);
343340
})();
344341

345342
await (async function() {
@@ -380,6 +377,22 @@ async function tests() {
380377
for await (const b of r) {
381378
}
382379
})();
380+
381+
await (async () => {
382+
console.log('destroy mid-stream does not error');
383+
const r = new Readable({
384+
objectMode: true,
385+
read() {
386+
this.push('asdf');
387+
this.push('hehe');
388+
}
389+
});
390+
391+
// eslint-disable-next-line no-unused-vars
392+
for await (const a of r) {
393+
r.destroy(null);
394+
}
395+
})();
383396
}
384397

385398
// to avoid missing some tests if a promise does not resolve

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.