Skip to content

stream: readable.push returns true at internal buffer size equal highWaterMark #10214

Description

@zbinlin
  • Version: v7.2.1
  • Platform: Arch linux 4.8.12-2 x86_64
  • Subsystem: stream
const { Readable } = require("stream");

const readable = new Readable({
    objectMode: true,
    highWaterMark: 1,
    read() {
        push("inside call:");
    },
});

const lines = [];

function push(w) {
    while (lines.length) {
        const state = readable._readableState;
        console.log(w, "before push,", state.length, state.buffer.length, state.highWaterMark);
        const ret = readable.push(lines.shift());
        console.log(w, "after push,", "return:", ret, state.length, state.buffer.length, state.highWaterMark);
        if (!ret) {
            break;
        }
    }
}

setTimeout(() => {
    lines.push("foo", "bar");
    push("outside call:");
});

readable.on("data", function (data) {
    readable.pause();
});

On above testcase code, it will output:

outside call: before push, 0 0 1
inside call: before push, 0 0 1
inside call: after push, return: false 1 1 1
outside call: after push, return: true 1 1 1

expect output:

outside call: before push, 0 0 1
inside call: before push, 0 0 1
inside call: after push, return: false 1 1 1
outside call: after push, return: false 1 1 1

Activity

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