Skip to content

stream/iter: toWritable() duplicates writes when writeSync() returns false after accepting chunk #63359

@trivikr

Description

@trivikr

Version

26.1.0

Platform

macOS 26.5.0

Subsystem

stream

What steps will reproduce the bug?

import { push, text, toWritable } from 'node:stream/iter';

const { writer, readable } = push({ highWaterMark: 1, backpressure: 'block' });
const writable = toWritable(writer);

await new Promise((resolve, reject) => {
  writable.write('a', (err) => err ? reject(err) : resolve());
});

writable.write('b');
writable.end();

console.log(await text(readable)); // abb, expected ab

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

Always

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

ab

The adapter should not write the same chunk twice; the repro should output ab.

What do you see instead?

abb

toWritable() retries via writer.write() when PushWriter.writeSync() returns false, even though PushWriter already accepted the chunk under backpressure: 'block', producing abb.

Additional information

No response

Metadata

Metadata

Assignees

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