Skip to content

Fix ChildProcess pipelines hanging on undrained output from earlier stages - #11009

Open
Marve10s wants to merge 1 commit into
Effect-TS:mainfrom
Marve10s:fix/childprocess-pipeline-drain
Open

Marve10s wants to merge 1 commit into
Effect-TS:mainfrom
Marve10s:fix/childprocess-pipeline-drain

Conversation

@Marve10s

Copy link
Copy Markdown
Contributor

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

A pipeline built with ChildProcess.pipeTo hangs forever when a stage before the last one writes more than about 128 KiB (about 1 MiB on Bun) to an output that is not piped to the next stage. Examples are a first stage that logs heavily to stderr with the default from: "stdout", the documented make\my-program`.pipe(pipeTo(make`grep error`, { from: "stderr" }))when the program writes normal stdout, or a busy middle stage of three. The same command run on its own completes, because theChildProcessSpawner` helpers drain output they do not return (#9846).

In the PipedCommand case every stage is spawned with piped stdout and stderr, but only the stream forwarded to the next stage is read. The other output is never read and is not reachable from the returned handle, so the stage blocks writing to a full pipe, never closes the stream it forwards, and the last stage never sees EOF.

Each non-final stage's unforwarded outputs are now drained and discarded in a fiber owned by that stage's scope, and the forwarded stream joins that fiber through Stream.drainFork, the same primitive #9846 uses. Draining lasts for the stage's lifetime, so a stage that closes its forwarded output early and keeps writing to the other one still completes. A drain failure while the forwarded stream is open (for example a failing Sink on stage 1's stderr) fails the next stage's input, as it does for the single-command helpers. Outputs that are not piped (inherit, ignore, a file descriptor) are already empty streams, so explicit options are unchanged. Inheriting the unforwarded outputs, as a shell does for stderr, was not used because it would print a stage's output to the host process's terminal.

The Node spawner (also used by Bun) covers from: "stdout", "stderr", "all" and "fdN" plus other output file descriptors; the Deno spawner covers stdout, stderr and all. On Deno, the drain releases its reader lock rather than cancelling the stream when the scope closes, so an unref'd stage that is still running keeps an open pipe, as before.

Verification

The same probe on both versions; stage 1 is sh -c 'head -c 300000 /dev/zero >&2; echo payload' piped to cat, with a 2 second timeout:

effect@4.1.7 / @effect/platform-node@4.1.7 and main:
control, single command string: "payload\n" (9ms)
control, pipeline with first stderr ignored: "payload\n" (5ms)
pipeline string: timed out after 2s (2007ms)
pipeline exitCode: timed out after 2s (2007ms)
pipeline handle.stdout: timed out after 2s (2004ms)
pipeline from stderr (JSDoc example shape): timed out after 2s (2006ms)

this branch:
control, single command string: "payload\n" (9ms)
control, pipeline with first stderr ignored: "payload\n" (5ms)
pipeline string: "payload\n" (5ms)
pipeline exitCode: 0 (5ms)
pipeline handle.stdout: "payload\n" (4ms)
pipeline from stderr (JSDoc example shape): "error-line\n" (5ms)

The new shared-suite tests for heavy stderr from a non-final stage, heavy stdout with { from: "stderr" }, and output written after the forwarded stream ends time out without the fix on Node, the Node proxy process layer and Deno, and pass with it. The fourth test keeps an unref'd stage's pipe open after the scope closes on Deno. Root pnpm check and pnpm lint passed; the Node (222), Bun (6) and Deno (82 passed, 14 skipped) spawner tests and the effect process tests passed.

@changeset-bot

changeset-bot Bot commented Nov 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e932232

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 40 packages
Name Type
@effect/platform-node-shared Patch
@effect/platform-deno Patch
@effect/platform-bun Patch
@effect/platform-node Patch
effect Patch
@effect/opentelemetry Patch
@effect/vitest Patch
@effect/ai-amazon-bedrock Patch
@effect/ai-anthropic Patch
@effect/ai-cloudflare Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/ai-typesafe Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/chat-discord Patch
@effect/chat-slack Patch
@effect/chat-teams Patch
@effect/chat-telegram Patch
@effect/chat-whatsapp Patch
@effect/platform-browser Patch
@effect/platform-cloudflare Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/docgen Patch
@effect/doctest Patch
@effect/graphql-generator Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@effect-janitor effect-janitor Bot added the 4.0 label Nov 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
arbitrary-combinators.ts 40.28 KB 40.28 KB 0.00 KB (0.00%)
basic.ts 6.60 KB 6.60 KB 0.00 KB (0.00%)
batching.ts 11.65 KB 11.65 KB 0.00 KB (0.00%)
brand.ts 7.17 KB 7.17 KB 0.00 KB (0.00%)
cache.ts 11.83 KB 11.83 KB 0.00 KB (0.00%)
config.ts 23.75 KB 23.75 KB 0.00 KB (0.00%)
differ.ts 22.55 KB 22.55 KB 0.00 KB (0.00%)
http-client.ts 28.40 KB 28.40 KB 0.00 KB (0.00%)
http-router.ts 39.10 KB 39.10 KB 0.00 KB (0.00%)
logger.ts 12.26 KB 12.26 KB 0.00 KB (0.00%)
metric.ts 9.91 KB 9.91 KB 0.00 KB (0.00%)
optic.ts 7.43 KB 7.43 KB 0.00 KB (0.00%)
pubsub.ts 16.55 KB 16.55 KB 0.00 KB (0.00%)
queue.ts 13.44 KB 13.44 KB 0.00 KB (0.00%)
schedule.ts 12.27 KB 12.27 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 14.32 KB 14.32 KB 0.00 KB (0.00%)
schema-binary.ts 43.17 KB 43.17 KB 0.00 KB (0.00%)
schema-class.ts 22.31 KB 22.31 KB 0.00 KB (0.00%)
schema-codegen.ts 33.66 KB 33.66 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 30.76 KB 30.76 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 28.49 KB 28.49 KB 0.00 KB (0.00%)
schema-string-transformation.ts 16.06 KB 16.06 KB 0.00 KB (0.00%)
schema-string.ts 12.60 KB 12.60 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.62 KB 16.62 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 39.82 KB 39.82 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 21.44 KB 21.44 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 21.62 KB 21.62 KB 0.00 KB (0.00%)
schema-toFormatter.ts 21.71 KB 21.71 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 26.75 KB 26.75 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 21.77 KB 21.77 KB 0.00 KB (0.00%)
schema.ts 21.41 KB 21.41 KB 0.00 KB (0.00%)
stm.ts 14.77 KB 14.77 KB 0.00 KB (0.00%)
stream.ts 10.56 KB 10.56 KB 0.00 KB (0.00%)
supervisor.ts 11.85 KB 11.85 KB 0.00 KB (0.00%)

This branch is waiting to be deployed

1 waiting deployment
fork — e9322326 Waiting Nov 27, 2026 by Marve10s via approval-gate #27805
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant