- Version: 12.18.1 and newer
- Platform: Darwin watson 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64
- Subsystem: stream
What steps will reproduce the bug?
Run this code on Node.js 12.18.1 or newer and notice how the error is emitted on b twice. On any older Node.js version it's only emitted once.
const { Readable, PassThrough, Writable, pipeline } = require('stream')
const a = new Readable({
read () {
this.destroy(new Error('foo'));
}
})
const b = new PassThrough()
const c = new Writable()
a.once('error', (err) => {
console.log('emitting error on b')
b.emit('error', err) // Note: you're not supposed to emit error manually!
})
b.on('error', (err) => {
console.log('b got error:', err.message)
})
pipeline(a.pipe(b), c, (err) => {
console.log('end of pipeline, err:', err.message)
})
If I change b.emit('error', err) to b.destroy(err) the error goes away. Using destroy is best practise and the user isn't supposed to emit error events manually on streams like in the above code. However, this was how we told users to do it previously, so a lot of code most likely exists in the wild expecting this to be possible and emitting the same error twice can have bad consequences.
Thoughts:
- It would be cool if we could warn users if they manually emitted an
error event on a stream.
- It would be nice if we could make this odd behaviour go away even if the user emits
error manually.
This regression was most likely introduced in #30869.
What steps will reproduce the bug?
Run this code on Node.js 12.18.1 or newer and notice how the error is emitted on
btwice. On any older Node.js version it's only emitted once.If I change
b.emit('error', err)tob.destroy(err)the error goes away. Usingdestroyis best practise and the user isn't supposed to emiterrorevents manually on streams like in the above code. However, this was how we told users to do it previously, so a lot of code most likely exists in the wild expecting this to be possible and emitting the same error twice can have bad consequences.Thoughts:
errorevent on a stream.errormanually.This regression was most likely introduced in #30869.