Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplex/Transform stream writableObjectMode ignored #39781

Closed
ccarcaci opened this issue Aug 16, 2021 · 1 comment
Closed

Duplex/Transform stream writableObjectMode ignored #39781

ccarcaci opened this issue Aug 16, 2021 · 1 comment

Comments

@ccarcaci
Copy link

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

@ccarcaci
Copy link
Author

N/A.
I've misunderstood the API doc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant