Skip to content

Readable streams with highWaterMark: 0 terminate earlyΒ #24915

@Rantanen

Description

@Rantanen
  • Version: v10.10.0, v11.4.0
  • Platform: Linux 4.4.0-45-generic deprecate domainsΒ #66-Ubuntu SMP Wed Oct 19 14:12:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
  • Subsystem: Streams

#20503 fixed things with highWaterMark: 0 streams. As far as I could tell, this was merged into v10.9.0.

However the following code still fails in v10.10.0 and v11.4.0:

let util = require('util');
let Readable = require('stream').Readable;

function MyStream() {
    Readable.call(this, { highWaterMark: 0 });
}
util.inherits(MyStream, Readable);

MyStream.prototype._read = function(n, fn) {
    console.log(`_read`);

    // Just keep emitting new data, but do that asynchronously.
    process.nextTick( () => {
        console.log('push');
        this.push('a');
    });
}

let s = new MyStream();
s.on('data', () => {
    console.log('data');
});

The MyStream implementation is supposed to continue emitting 'a' without terminating. However the output of that is:

_read
push
data

If I change the constructor into { highWaterMark: 1 } I get the expected infinite push/data cycle.

Metadata

Metadata

Assignees

No one assigned

    Labels

    streamIssues and PRs related to the stream subsystem.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions