Skip to content

process: restore stdio blocking mode before execve - #66826

Closed
fengmk2 wants to merge 3 commits into
nodejs:mainfrom
fengmk2:fix/execve-stdio-flags
Closed

fengmk2 wants to merge 3 commits into
nodejs:mainfrom
fengmk2:fix/execve-stdio-flags

Conversation

@fengmk2

@fengmk2 fengmk2 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Opening a standard stream can set O_NONBLOCK on its file descriptor. process.execve() passes this state to the replacement program, where I/O can fail with EAGAIN.

Restore the startup blocking mode for standard descriptors that still refer to their original files or streams. Preserve other status flags and terminal settings. Save all standard stream flags before changes, and restore them if execution fails. This also handles shared stdout and stderr descriptors, such as 2>&1.

Fixes: #66824

Codex (GPT-6) helped investigate and fix this issue.

Restore the startup O_NONBLOCK state of standard descriptors before
execve(), preserving other file status flags and terminal settings.
Save all flags before changing them so failed calls also restore
shared stdout and stderr correctly.

Assisted-by: Codex
Signed-off-by: MK <fengmk2@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Oct 18, 2026
Save errno and restore the descriptor and status flags before creating
an error, whose inherited property setters can execute JavaScript.
Check the flags from an inherited setter while the child remains alive.
Keep the test cases and assertions in JavaScript and use Python for
the POSIX descriptor setup and observations.

Assisted-by: Codex
Signed-off-by: MK <fengmk2@gmail.com>
Restore stdio explicitly at both failure exits after saving errno and
before constructing the JavaScript error. Remove the cleanup scope and
error-routing variables while preserving the blocking-mode policy.
Clarify that the startup-mode check compares the underlying file.

Assisted-by: Codex
Signed-off-by: MK <fengmk2@gmail.com>
@fengmk2
fengmk2 marked this pull request as ready for review October 18, 2026 10:08
@codecov

codecov Bot commented Oct 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.00000% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.49%. Comparing base (e2d5522) to head (7f9bfc7).

Files with missing lines Patch % Lines
src/node_process_methods.cc 76.31% 7 Missing and 2 partials ⚠️
src/node.cc 50.00% 1 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66826      +/-   ##
==========================================
- Coverage   90.50%   90.49%   -0.01%     
==========================================
  Files         797      797              
  Lines      277793   277822      +29     
  Branches    53366    53369       +3     
==========================================
+ Hits       251405   251416      +11     
+ Misses      16801    16796       -5     
- Partials     9587     9610      +23     
Files with missing lines Coverage Δ
src/node_internals.h 80.35% <ø> (ø)
src/node.cc 79.19% <50.00%> (-0.39%) ⬇️
src/node_process_methods.cc 89.41% <76.31%> (+0.60%) ⬆️

... and 34 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fengmk2 fengmk2 closed this Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

process.execve() passes non-blocking stdio to the new program

2 participants