Skip to content

stream.PassThrough not draining (from Node 16) #40935

Description

@davedoesdev

Version

v16.13.0

Platform

Linux david-Latitude-E6440 5.13.0-21-generic #21-Ubuntu SMP Tue Oct 19 08:59:28 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

stream

What steps will reproduce the bug?

const { PassThrough } = require('stream');
const pt = new PassThrough({ highWaterMark: 0 });
pt.on('drain', () => console.log('drained'));
console.log(pt.write('hello'));
console.log(pt.writableLength, pt.writableNeedDrain);
console.log(pt.read().toString());
console.log(pt.writableLength, pt.writableNeedDrain);

How often does it reproduce? Is there a required condition?

Every time

What is the expected behavior?

On Node 14:

david@david-Latitude-E6440:/tmp$ node --version
v14.18.1
david@david-Latitude-E6440:/tmp$ node repro.js 
false
5 true
drained
hello
0 false

What do you see instead?

On Node 16:

david@david-Latitude-E6440:/tmp$ node --version
v16.13.0
david@david-Latitude-E6440:/tmp$ node repro.js 
false
5 true
hello
5 true

Additional information

No response

Activity

  1. added
    streamIssues and PRs related to Node.js streams.
    on Nov 23, 2021
  2. davedoesdev commented on Nov 24, 2021

    @davedoesdev
    ContributorAuthor

    I think this is due to the change to transforming the data on write instead of read.
    Therefore the readable length gets to 5 when write() is called, i.e. before read(), and https://github.com/nodejs/node/blame/master/lib/internal/streams/readable.js#L474 doesn't trigger.
    Whereas on Node 14, the length is 0 when read() is called so we see length less than watermark.
    Perhaps a highWaterMark of 0 isn't going to work going forward?
    FYI I'm using it for testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    streamIssues and PRs related to Node.js streams.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions