Skip to content

stream/iter: pipeTo() crashes when synchronous writev() returns undefined #63560

Description

@trivikr

Version

26.2.0

Platform

macOS 26.5.0

Subsystem

stream

What steps will reproduce the bug?

import { pipeTo } from 'node:stream/iter';

async function* source() {
  yield [new Uint8Array([65]), new Uint8Array([66])];
}

const chunks = [];
const writer = {
  write(chunk) {
    chunks.push(chunk);
  },
  writev(batch) {
    chunks.push(...batch);
    // Synchronous success: returns undefined.
  },
  end() {},
};

try {
  const bytes = await pipeTo(source(), writer);
  console.log('resolved:', bytes, Buffer.concat(chunks).toString());
} catch (err) {
  console.log('rejected:', `${err.name}: ${err.message}`);
}

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

Always

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

resolved: 2 AB

What do you see instead?

rejected: TypeError: Method Promise.prototype.then called on incompatible receiver undefined

piping into a custom writer that supports batched writes fails even though the writer successfully accepts the data synchronously. The same kind of synchronous success works for single writes, so batched writev() writes should complete normally instead of rejecting with a TypeError.

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