Skip to content

fix(child_process): make the std fd registry duplicates close-on-exec - #13613

Open
jgoux wants to merge 1 commit into
PerryTS:mainfrom
jgoux:fix/std-fd-dup-cloexec
Open

jgoux wants to merge 1 commit into
PerryTS:mainfrom
jgoux:fix/std-fd-dup-cloexec

Conversation

@jgoux

@jgoux jgoux commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The runtime kept duplicates of the process's stdin, stdout and stderr (and of a child's stdin pipe while draining it) created with plain dup(), without close-on-exec. Every child process spawned afterwards inherited those extra descriptors, including detached children started with stdio: "ignore". A detached daemon then held the parent's stdout and stderr pipes open, so whoever reads the parent's output never saw EOF after the parent exited. Node never leaks these descriptors into children. The duplicates are now created with F_DUPFD_CLOEXEC.

Changes

  • crates/perry-runtime/src/fs/mod.rs (std_fd_registry): duplicate fds 0-2 with fcntl(F_DUPFD_CLOEXEC).
  • crates/perry-runtime/src/child_process/reactor/stdin.rs (cp_spawn_stdin_drain): same for the long-lived duplicate of a child's stdin pipe.
  • crates/perry-runtime/src/child_process/options.rs (cp_stdio_from_fd): same for the transient duplicate made while building a child's stdio, which a concurrent spawn could inherit.
  • Regression test: test-files/test_gap_std_fd_dup_cloexec.ts. It writes to fds 1 and 2 first, then checks that fds 3-9 are closed in a piped child and in a detached stdio: "ignore" child.
  • Changelog fragment changelog.d/13613-std-fd-dup-cloexec.md.

Related issue

n/a. Found while compiling the Supabase CLI with Perry.

Test plan

The new test-files/ test runs in the gap suite, which compares its output against Node; it passes on my fork, along with the existing child_process and fs fd gap tests (run). test_issue_1934_spawn_reactor.ts fails in that run with an exit/end order difference; it fails the same way on the base commit without this change.

The full cargo build --release and cargo test --workspace runs are left to this PR's CI, so those two boxes are not ticked. cargo fmt on the touched Rust files is clean.

  • cargo build --release clean
  • cargo test --workspace --exclude perry-ui-ios --exclude perry-ui-tvos --exclude perry-ui-watchos --exclude perry-ui-gtk4 --exclude perry-ui-android --exclude perry-ui-windows passes
  • (if user-facing) Added or updated a test under test-files/ or a #[test] in the affected crate
  • (if CLI / stdlib / runtime API changed) Updated docs/src/
  • (if touching a platform UI backend) Built -p perry-ui-<backend> locally on that platform

Checklist

  • I have NOT bumped the workspace version or edited CHANGELOG.md (maintainer handles these at merge)
  • My commits follow the loose feat: / fix: / docs: / chore: prefix convention used in the log
  • I've read CONTRIBUTING.md and agree to the Code of Conduct

Summary by CodeRabbit

  • Bug Fixes
    • Child processes no longer inherit unintended copies of the parent’s standard input, output, and error streams.
    • Detached child processes now release the parent’s output pipes when appropriate, so readers can detect when output has finished.

@jgoux
jgoux force-pushed the fix/std-fd-dup-cloexec branch from 4d71562 to 8481762 Compare October 31, 2026 05:26
@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5e4f170a-b5ea-403c-9088-216ed36c5d03
Commits

Reviewing files that changed from the base of the PR and between 19a6de5 and 8481762.

Files selected for processing: 5
  • changelog.d/13613-std-fd-dup-cloexec.md
  • crates/perry-runtime/src/child_process/options.rs
  • crates/perry-runtime/src/child_process/reactor/stdin.rs
  • crates/perry-runtime/src/fs/mod.rs
  • test-files/test_gap_std_fd_dup_cloexec.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

Walkthrough

Unix standard descriptor duplicates now use F_DUPFD_CLOEXEC. A new test probes open descriptors in piped and detached child processes.

Changes: Standard descriptor duplication

Layer / File(s) Summary
Use close-on-exec for standard descriptor duplicates
crates/perry-runtime/src/child_process/options.rs, crates/perry-runtime/src/child_process/reactor/stdin.rs, crates/perry-runtime/src/fs/mod.rs
These Unix code paths now duplicate descriptors with F_DUPFD_CLOEXEC instead of dup.
Probe descriptors in child processes
test-files/test_gap_std_fd_dup_cloexec.ts, changelog.d/13613-std-fd-dup-cloexec.md
The test probes descriptors 3–9 in piped and detached children. The changelog describes standard-stream inheritance and its effect on EOF detection.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: proggeramlug

Merge Risk: Minimal · up to 84817

No actionable merge-blocking risk is established for this change.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title names the main change: the std fd registry duplicates are now created close-on-exec. It matches the raw summary and the objectives, which describe switching the duplicates to F_DUPFD_CLOEXEC…
Description check Passed The description follows the repository template. It has a Summary that states the problem and the fix, a Changes list with file paths, and a Related issue section that states n/a with a reason. The Te…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the std fd registry duplicates are now created close-on-exec. It matches the raw summary and the objectives, which describe switching the duplicates to F_DUPFD_CLOEXEC. It uses the conventional fix(scope): prefix and is specific enough for a reader scanning history.

Full details: Description check

Explanation

The description follows the repository template. It has a Summary that states the problem and the fix, a Changes list with file paths, and a Related issue section that states n/a with a reason. The Test plan lists the checkboxes and reports the gap test results and the one failing existing test. The Checklist is complete. The two unchecked build and test boxes are explained as deferred to CI. The Screenshots section is optional and omitted, which is acceptable.

Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 4 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant