fix(status): catch OSError in os.kill(pid, 0) for Windows compatibility (salvage #12490)#14504
Merged
Conversation
On Windows, os.kill(nonexistent_pid, 0) raises OSError with WinError 87
("The parameter is incorrect") instead of ProcessLookupError. Without
catching OSError, the acquire_scoped_lock() and get_running_pid() paths
crash on any invalid PID check — preventing gateway startup on Windows
whenever a stale PID file survives from a prior run.
Adapted @phpoh's fix in #12490 onto current main. The main file was
refactored in the interim (get_running_pid now iterates over
(primary_record, fallback_record) with a per-iteration try/except),
so the OSError catch is added as a new except clause after
PermissionError (which is a subclass of OSError, so order matters:
PermissionError must match first).
Co-authored-by: phpoh <1352808998@qq.com>
3 tasks
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.
Salvages #12490 by @phpoh onto current main.
On Windows,
os.kill(nonexistent_pid, 0)raisesOSErrorwith WinError 87 instead ofProcessLookupError. Two sites ingateway/status.pycaught only(ProcessLookupError, PermissionError)— any invalid PID check crashed on Windows, preventing gateway startup whenever a stale PID file survived.Applied:
acquire_scoped_lock(line ~499): widened except to includeOSErroralongside the existing tupleget_running_pid(line ~737): added a separateexcept OSError: continueclause AFTERexcept PermissionError:so PermissionError (an OSError subclass) still gets its dedicated branch firstThe PR's original patch didn't apply cleanly because main refactored
get_running_pidto iterate over primary/fallback records with a per-iteration try/except block. Functionally equivalent to @phpoh's original.Closes #12490. Author attribution preserved via
--author=.