Skip to content

stream/iter: pipeToSync() ignores writeSync() backpressure and overcounts bytes #63562

Description

@trivikr

Version

26.2.0

Platform

macOS 26.5.0

Subsystem

stream

What steps will reproduce the bug?

import { setTimeout as delay } from 'node:timers/promises';
import { pipeToSync, push } from 'node:stream/iter';

const decoder = new TextDecoder();
const { writer, readable } = push({ highWaterMark: 1 });

const total = pipeToSync(['a', 'b'], writer, { preventClose: true });

const iter = readable[Symbol.asyncIterator]();
const first = await iter.next();

const second = await Promise.race([
  iter.next().then((r) => r.done ? '<done>' : decoder.decode(r.value[0])),
  delay(20, '<no second chunk>'),
]);

await iter.return?.();

console.log(`pipeToSync returned: ${total}`);
console.log(`first buffered chunk: ${decoder.decode(first.value[0])}`);
console.log(`second buffered chunk: ${second}`);

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

Always

What is the expected behavior? Why is that the expected behavior?

pipeToSync returned: 1
first buffered chunk: a
second buffered chunk: <no second chunk>

pipeToSync() should throw or otherwise signal that the second sync write was not accepted. It should not count bytes for a chunk when writeSync() or writevSync() returns false without accepting the data.

What do you see instead?

pipeToSync returned: 2
first buffered chunk: a
second buffered chunk: <no second chunk>

pipeToSync() reports that 2 bytes were written even though the strict push({ highWaterMark: 1 }) writer only accepted a. The failed writeSync('b') return value is ignored, so data is silently dropped and byte accounting is incorrect.

Additional information

No response

Activity

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

Metadata

Metadata

Assignees

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