diff --git a/lib/internal/streams/async_iterator.js b/lib/internal/streams/async_iterator.js index 9ca8e5ebe23b15..0e34573d877aee 100644 --- a/lib/internal/streams/async_iterator.js +++ b/lib/internal/streams/async_iterator.js @@ -58,7 +58,7 @@ function onError(iter, err) { iter[kLastReject] = null; reject(err); } - iter.error = err; + iter[kError] = err; } function wrapForNext(lastPromise, iter) { diff --git a/test/parallel/test-stream-readable-async-iterators.js b/test/parallel/test-stream-readable-async-iterators.js index b1801a1db3e580..39761b413260f1 100644 --- a/test/parallel/test-stream-readable-async-iterators.js +++ b/test/parallel/test-stream-readable-async-iterators.js @@ -115,6 +115,18 @@ async function tests() { readable.destroy(new Error('kaboom')); })(); + await (async function() { + console.log('call next() after error'); + const readable = new Readable({ + read() {} + }); + const iterator = readable[Symbol.asyncIterator](); + + const err = new Error('kaboom'); + readable.destroy(new Error('kaboom')); + await assert.rejects(iterator.next.bind(iterator), err); + })(); + await (async function() { console.log('read object mode'); const max = 42;