Repository navigation
fix(daemon): treat an unopenable Windows process as alive - #577
Open
columbia11 wants to merge 7 commits into
Open
columbia11 wants to merge 7 commits into
columbia11 wants to merge 7 commits into
Conversation
pid_alive is documented to return true when a process with that pid exists, and the Unix branch treats EPERM as alive. On Windows every OpenProcess failure returned false, including ERROR_ACCESS_DENIED, which means the process exists but this caller may not open it (for example a SYSTEM or elevated process). A pid with no process fails with ERROR_INVALID_PARAMETER. Return true for ERROR_ACCESS_DENIED, matching the Unix EPERM case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
lockfile::pid_aliveis documented to returntrue"if a process with that pid exists". The Unix branch does that and explicitly treatsEPERMas alive. The Windows branch returnsfalsefor everyOpenProcess(PROCESS_SYNCHRONIZE)failure, includingERROR_ACCESS_DENIED, which means the process exists but this caller may not open it.Measured on Windows 11 from an unelevated PowerShell:
OpenProcess(SYNCHRONIZE)pid_alivebeforeERROR_ACCESS_DENIED)falsetrueERROR_INVALID_PARAMETER)falseA process started from an elevated terminal is not openable from an unelevated one in the same way.
pid_alivefeedsdaemon stopcleanup (ensure!(!pid_alive(expected.pid))before removingdaemon.json),daemon_info::read_valid, the post-update wait for the predecessor process, and update-leftover cleanup. In each of these, a live but unopenable process was treated as gone.Fix
When
OpenProcessfails, returnGetLastError() == ERROR_ACCESS_DENIED, matching the UnixEPERMcase. A nonexistent pid still fails withERROR_INVALID_PARAMETERand staysfalse. pid 0 andu32::MAXare unchanged and still covered by the existing tests.Tests
existing_process_that_cannot_be_opened_is_alive:pid_alive(4)(the System process). Unelevated callers getERROR_ACCESS_DENIED; elevated callers such as the CI runner can open it. It passes either way after the fix.cargo test -p bsk --lib daemon::lockfile::testson Windows 11, unelevated: 4 passed. With the oldreturn falserestored, the new test fails (3 passed, 1 failed).rustfmt --check: clean.I used Claude Code to find this, write the fix and test, and run the checks above.
🤖 Generated with Claude Code