Skip to content

Closing WritableStream from TransformStream causes Node.js process to crash #54453

Open
@JAD3N

Description

@JAD3N

Version

v20.16.0

Platform

Linux laptop 6.1.0-23-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.99-1 (2024-07-15) x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

I ran this code and my Node.js process crashed with no output:

This causes a crash:

import { TransformStream } from "node:stream/web";

const { writable } = new TransformStream();

try {
  let writer = writable.getWriter();
  await writer.write(" ");
  writer.releaseLock();

  writer = writable.getWriter();
  await writer.close();
  writer.releaseLock();

  console.log("Done!");
} catch (err) {
  console.error("Error:", err);
}

This doesn't:

const stream = new WritableStream();

try {
  let writer = stream.getWriter();
  await writer.write(" ");
  writer.releaseLock();

  writer = stream.getWriter();
  await writer.close();
  writer.releaseLock();

  console.log("Done!");
} catch (err) {
  console.error("Error:", err);
}

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

If I close the WritableStream on the TransformStream example without awaiting the close() promise then the process will proceed to log Done!.

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

I figured the stream would close or throw some kind of error if it cannot.

What do you see instead?

The Node.js process crashes without any thrown errors and doesn't trigger the beforeExit or exit process events.

Additional information

I've simplified my code into the reproducible above, that's why I create multiple writers.

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions