Skip to content

fix(self-update): wait on inherited parent handles on Windows - #5105

Open
Cloud0310 wants to merge 1 commit into
rust-lang:mainfrom
Cloud0310:uninstall-refactor
Open

Cloud0310 wants to merge 1 commit into
rust-lang:mainfrom
Cloud0310:uninstall-refactor

Conversation

@Cloud0310

Copy link
Copy Markdown
Contributor

Motivation

This PR fixes the PID reuse race described here:

// FIXME: Using the process ID exposes a race condition
// wherein the parent process already exited and the OS
// reassigned its ID.
let parent_id = entry.th32ParentProcessID;

Method

  • Add spawn_with_parent_handle to launch a subprocess with an inherited handle to its parent process.
  • Pass the handle value through the RUSTUP_PARENT_HANDLE environment variable so the subprocess can wait for its parent to exit.

Compatibility

Older rustup versions do not pass a parent process handle value when launching the self-updater.
So the original wait_for_parent implementation is renamed as wait_for_parent_legacy and used when RUSTUP_PARENT_HANDLE is absent.

Tests

Add self_replace_waits_for_legacy_parent to simulate an older launcher starting the new updater without passing a parent handle, covering compatibility with older rustup versions that use the old parent PID protocol.

@Cloud0310

Copy link
Copy Markdown
Contributor Author

@ChrisDenton I am thinking your previous suggestion upon using stdin for passing handles in #5088 (review).
If you think using a little bit of unsafe code as this new PR does in new spawn_with_handle function, I guess I would love to switch over to the new func.

@rustbot

rustbot commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (possibly #5106) made this pull request unmergeable. Please resolve the merge conflicts.

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.

2 participants