Skip to content

stream/iter: fromWritable().writev() leaves Writable corked when chunk validation throwsΒ #63294

@trivikr

Description

@trivikr

Version

26.1.0

Platform

macOS 26.5.0

Subsystem

stream

What steps will reproduce the bug?

import { strictEqual, throws } from "node:assert";
import { Writable } from "node:stream";
import { fromWritable } from "node:stream/iter";

const writable = new Writable({
  write(chunk, enc, cb) {
    cb();
  },
});

const writer = fromWritable(writable);

throws(() => writer.writev([new Uint8Array([1]), 42]), {
  code: "ERR_INVALID_ARG_TYPE",
});

// Expected: writev() should uncork even when a later chunk conversion throws.
strictEqual(writable.writableCorked, 0);

Run with

node --experimental-stream-iter repro.js

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

Always

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

fromWritable().writev() should either complete the batched write or throw/reject without changing the underlying Writable’s corking state. If writev() internally calls writable.cork(), it should always pair that with writable.uncork(), including when converting or validating a later chunk throws.

What do you see instead?

Calling writer.writev([new Uint8Array([1]), 42]) throws ERR_INVALID_ARG_TYPE, but the wrapped classic Writable remains corked afterward (writable.writableCorked === 1). This happens because writev() corks before converting all chunks, and if toUint8Array() throws for a later chunk, the uncork() call is skipped.

Additional information

No response

Metadata

Metadata

Assignees

Labels

streamIssues and PRs related to the stream subsystem.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions