Skip to content

stream: fix async iterator return when destroyed earlier

Unfortunately, https://github.com/nodejs/node/pull/31314 introduced a regression that made the loop not terminate:

'use strict'

const { Readable } = require('stream')

const r = new Readable({
  read () {}
})

r.destroy()

async function run () {

  for await (let chunk of r) {
  }
}

r.on('close', () => {
  console.log('close emitted')
  run().then(() => console.log('finished'))
})

I see that as more critical as an error not being forwarded. See https://github.com/nodejs/node/pull/31314#issuecomment-578397279 for more details.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

Merge request reports

Loading