-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
Description
Version
14.17.5
Platform
Linux *** 5.11.0-25-generic #27~20.04.1-Ubuntu SMP Tue Jul 13 17:41:23 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
Create an usual Transform stream with writableObjectMode: true.
i.e.
type Packet = { ... }
const packetParser = (): stream.Transform => {
const transformStream = new stream.Transform({
writableObjectMode: true,
transform(packet: Buffer, _, callback) {
const parsedPacketObject: Packet = parser.parse(packet)
this.push(parsedPacketObject)
callback()
},
})
return transformStream
}
Following the cascade calls of this.push() I went into:
https://github.com/nodejs/node/blob/v14.17.5/lib/internal/streams/readable.js#L203
this line calls the readableAddChunk() function which is not taking into account the writableObjectMode flag in line: https://github.com/nodejs/node/blob/v14.17.5/lib/internal/streams/readable.js#L217
This results into the exception:
Exception has occurred: TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of Packet
How often does it reproduce? Is there a required condition?
No, it is reproducing all the times.
What is the expected behavior?
The when I call push I expect to call the writable part of Transform/Duplex stream which takes into account the writableObjectMode flag.
What do you see instead?
I see that the push call goes through the readable part of Transform/Duplex stream.
Additional information
No response