diff --git a/lib/internal/streams/readable.js b/lib/internal/streams/readable.js index 9dff2013a41da5..53cda0fd8f4723 100644 --- a/lib/internal/streams/readable.js +++ b/lib/internal/streams/readable.js @@ -1113,8 +1113,10 @@ async function* createAsyncIterator(stream, options) { const chunk = stream.destroyed ? null : stream.read(); if (chunk !== null) { yield chunk; - } else if (error !== undefined) { - break; + } else if (error) { + throw error; + } else if (error === null) { + return; } else { await new Promise(next); }