Skip to content

Commit 2cd9892

Browse files
mcollinaTrott
authored andcommitted
Revert "stream: fix async iterator destroyed error propagation"
This reverts commit d15b8ea. PR-URL: #31508 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent 64161f2 commit 2cd9892

File tree

2 files changed

+11
-30
lines changed

2 files changed

+11
-30
lines changed

lib/internal/streams/async_iterator.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,18 @@ const ReadableStreamAsyncIteratorPrototype = ObjectSetPrototypeOf({
106106
}
107107

108108
if (this[kStream].destroyed) {
109+
// We need to defer via nextTick because if .destroy(err) is
110+
// called, the error will be emitted via nextTick, and
111+
// we cannot guarantee that there is no error lingering around
112+
// waiting to be emitted.
109113
return new Promise((resolve, reject) => {
110-
if (this[kError]) {
111-
reject(this[kError]);
112-
} else if (this[kEnded]) {
113-
resolve(createIterResult(undefined, true));
114-
} else {
115-
finished(this[kStream], (err) => {
116-
if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') {
117-
reject(err);
118-
} else {
119-
resolve(createIterResult(undefined, true));
120-
}
121-
});
122-
}
114+
process.nextTick(() => {
115+
if (this[kError]) {
116+
reject(this[kError]);
117+
} else {
118+
resolve(createIterResult(undefined, true));
119+
}
120+
});
123121
});
124122
}
125123

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -567,23 +567,6 @@ async function tests() {
567567
assert.strictEqual(e, err);
568568
})()]);
569569
}
570-
571-
{
572-
const _err = new Error('asd');
573-
const r = new Readable({
574-
read() {
575-
},
576-
destroy(err, callback) {
577-
setTimeout(() => callback(_err), 1);
578-
}
579-
});
580-
581-
r.destroy();
582-
const it = r[Symbol.asyncIterator]();
583-
it.next().catch(common.mustCall((err) => {
584-
assert.strictEqual(err, _err);
585-
}));
586-
}
587570
}
588571

589572
{

0 commit comments

Comments
 (0)