Skip to content

Track programs given a shared >> handle by process handle, not id - #21

Merged
hex2f merged 1 commit into
hex2f:mainfrom
ExpectedArgument:append-children-by-handle
Nov 6, 2026
Merged

hex2f merged 1 commit into
hex2f:mainfrom
ExpectedArgument:append-children-by-handle

Conversation

@ExpectedArgument

Copy link
Copy Markdown

A follow-up to the PID reuse note in the review of #6.

AppendFile kept the process ids of the programs started with a shared >> handle and checked them with pid_alive. If one of them exited and Windows gave its id to an unrelated process, the entry, and with it the open file, stayed until that process exited, so rm log could fail for a while.

It now keeps a handle to each such process, a duplicate of the Child's own (try_clone_to_owned), and drops it once WaitForSingleObject says the process has exited (sys::process_running). A handle can't come to mean another process, and holding it keeps the id from being reused while we track it. pid_alive stays for kill -0.

Tests

  • PID reuse can't be forced from a test, so there is no new compat script. 066_msys_append_concurrent.sh covers the behaviour this keeps: concurrent appends, and removing and recreating the file right after an MSYS program appended to it. It passed 5 runs out of 5.
  • cargo test passes: unit tests, 70/70 compat scripts and msys_tmp. No new clippy warnings.

AppendFile kept the process ids of programs started with a shared >> handle and checked them with pid_alive. If one exited and Windows gave its id to an unrelated process, the entry, and the open file, stayed until that process exited, so rm log could fail for a while. Keep a handle to each process instead and check whether it has exited, as suggested in the review of hex2f#6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@hex2f hex2f left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for following up on this. Holding a duplicate of the child's process handle fixes the PID-reuse problem: a handle can't come to mean another process, and holding it keeps the ID from being reused anyway. process_running only needs SYNCHRONIZE, and the Child handle has it.

I merged it onto current main: cargo test passes 70/70, and 066_msys_append_concurrent passed 6 runs out of 6. Together with #10 and #11 it passes 72/72. No new clippy warnings.

Looks good to merge.

@hex2f
hex2f merged commit 95cc56c into hex2f:main Nov 6, 2026
1 check passed
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.

2 participants