Open markddrake opened 3 days ago
Sorry - Missed the commands and version from the 22.9 t/c
C:\Development\YADAMU\src\scratch\streams>docker cp input.txt NODE-LATEST:/tmp
C:\Development\YADAMU\src\scratch\streams>docker cp test1.js NODE-LATEST:/tmp
C:\Development\YADAMU\src\scratch\streams>docker exec -it NODE-LATEST bash
root@0cd652c8fcb1:/# node -v
v22.9.0
root@0cd652c8fcb1:/# cd tmp
root@0cd652c8fcb1:/tmp# node test1.js
``
I have tried wrapping the return finished and Promise.allSettled in try/catch but still get the unhandled rejection
const { PassThrough} = require('stream');
const { pipeline, finished, } = require('stream/promises');
const fs = require('fs');
class MyTransform extends PassThrough {
constructor(is) {
super()
this.is = is
this.counter = 0
}
async _transform(data,enc,callback) {
this.counter++
this.push(data)
if (this.counter > 100) {
this.is.close()
}
callback()
}
}
async function runPipeline() {
const is = fs.createReadStream('input.txt')
is.on('error',(err) => {
console.log(is.constructor.name,err)
})
const t = new MyTransform(is)
t.on('error',(err) => {
console.log(t.constructor.name,err)
})
const os = fs.createWriteStream('output.txt')
os.on('error',(err) => {
console.log(os.constructor.name,err)
})
const streams = [is,t,os]
const activeStreams = streams.map((s) => {
try {
return finished(s)
} catch (e) {
console.log('WTF-FINISHED',e)
}
})
console.log(activeStreams)
try {
await pipeline(...streams);
console.log(t.counter)
} catch (err) {
console.log(1)
console.log(activeStreams)
try {
await Promise.allSettled(activeStreams)
} catch (e) {
console.log('WTF-ALL-S',e)
}
console.log(2)
console.log(activeStreams)
console.error('Pipeline error:', err);
}
}
process.on('unhandledRejection', (e,p) => {
console.log("Unhandled",e,p)
})
runPipeline().then(() => {console.log('success')}).catch((e) => {console.log(e)})
The only workaround i have it to flag the error as handled in the stream on error and ignore it in the unhandled rejection code. It appears to be that finished must be throwing the exception, but I do not seem to be able to catch it, and I do not think it should be throwing anyway.
Version
22.9.0 (Docker Latest)
Platform
Subsystem
STREAMS/PROMISES FINISHED
What steps will reproduce the bug?
Run the following code on 22.2 and 22.9 and note changed behavior - Unhandled Rejection
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
The 22.2.0 Behavoir appears to be correct to me
What do you see instead?
Additional information
No response