Skip to content

fix: avoid duplicate buffered writes when IO.Process.output exec fails#13464

Merged
kim-em merged 1 commit intoleanprover:masterfrom
kim-em:issue-13463
Apr 28, 2026
Merged

fix: avoid duplicate buffered writes when IO.Process.output exec fails#13464
kim-em merged 1 commit intoleanprover:masterfrom
kim-em:issue-13463

Conversation

@kim-em
Copy link
Copy Markdown
Collaborator

@kim-em kim-em commented Apr 18, 2026

This PR replaces exit(-1) with _exit(-1) in the forked child branches of lean_io_process_spawn (the chdir failure and execvp failure paths). exit flushes inherited C stdio buffers, which share underlying file descriptors with the parent. If the parent had a file handle open with unflushed data, that data would be written to the file in the child and then again when the parent later flushes, resulting in duplicated output. _exit skips the stdio flush, so the parent's buffered writes are no longer duplicated into inherited files.

Closes #13463.

🤖 Prepared with Claude Code

This PR replaces `exit(-1)` with `_exit(-1)` in the forked child branches
of `lean_io_process_spawn` (the `chdir` failure and `execvp` failure
paths). `exit` flushes inherited C stdio buffers, which share underlying
file descriptors with the parent. If the parent had a file handle open
with unflushed data, that data would be written to the file in the child
and then again when the parent later flushes, resulting in duplicated
output. `_exit` skips the stdio flush, so the parent's buffered writes
are no longer duplicated into inherited files.

Closes leanprover#13463.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@kim-em kim-em added the changelog-compiler Compiler, runtime, and FFI label Apr 18, 2026
@github-actions github-actions Bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Apr 18, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 3e9ed3c29dfa31db6bd7d701b45b152bea22f3e8 --onto fed2f32651e1e24a507c12aae234ac59e4d9916a. You can force Mathlib CI using the force-mathlib-ci label. (2026-04-18 09:08:11)

@leanprover-bot
Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 3e9ed3c29dfa31db6bd7d701b45b152bea22f3e8 --onto 3fc99eef102549c743c6c63547983319bfae6f01. You can force reference manual CI using the force-manual-ci label. (2026-04-18 09:08:13)

@kim-em kim-em added this pull request to the merge queue Apr 27, 2026
Merged via the queue into leanprover:master with commit 2ad0f96 Apr 28, 2026
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-compiler Compiler, runtime, and FFI toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IO.Process.output duplicates buffered file writes when exec fails

2 participants