Skip to content

Process.run: a grandchild that keeps writing makes C answer Fail where JS answers Done #1051

Closed

Description

@nicolas-abril

Behavior

When the direct child exits but a background grandchild keeps writing to the inherited stdout, the C lane and the JS lane answer different things:

Process.run("/bin/sh", ["-c", "yes & echo hi"], "", 65536, 1500)
Lane Result
native C Fail{(27, "File too large")} (output past max_output)
JS (Bun) Done{(0, ("hi\n", ""))}

Observed on macOS arm64 on main at 168534f, right after #1030. Both lanes leave the yes running, as the guide documents ("Timeouts do not kill descendants").

Cause

After #1030's review, the C loop in bend2/effs/process_run.c (process_call, lines 161–205) reaps the direct child on every pass. Once it has exited, the loop polls with a 0 ms timeout and stops only when a poll returns nothing ready (line 205) or every pipe is closed (line 189). A grandchild that never stops writing keeps the pipe readable, so the loop keeps draining until the output passes max_output. The deadline no longer applies at that point either (line 175 checks it only while the child is alive).

A grandchild that writes slowly ((while :; do echo x; sleep 0.01; done) & echo hi) does not trigger it: the drain finds an empty poll and stops, and both lanes answer Done. They differ only in how many x lines they catch, which is a timing race.

It cannot hang, because the output stays capped by max_output, but the two lanes should answer the same thing.

Possible fix

Once the direct child has been reaped, drain in a single pass: read only what is readable at that moment (for example, bounded by FIONREAD per pipe, or by one poll and read round), then stop. That matches what the guide promises ("The call waits for the direct child and drains ready output; a descendant holding an inherited pipe open does not extend the wait") and what Bun.spawnSync does.

A test in tests/io/process_run.bend with the call above and an exact expected result would keep the lanes in step.

Activity

  1. added
    bug
    on Sep 25, 2026
  2. added a commit that references this issue on Sep 25, 2026
    11c65a2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions