Skip to content

Duplex/Transform stream writableObjectMode ignored #39781

@ccarcaci

Description

@ccarcaci

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions