fix(gateway): retry detached restart helper without job breakaway on Windows - #67917
Closed
askie wants to merge 1 commit into
Closed
fix(gateway): retry detached restart helper without job breakaway on Windows#67917askie wants to merge 1 commit into
askie wants to merge 1 commit into
Conversation
…Windows When the gateway runs inside a job object that disallows breakaway (no JOB_OBJECT_LIMIT_BREAKAWAY_OK, e.g. under Task Scheduler), CreateProcess with CREATE_BREAKAWAY_FROM_JOB fails with ERROR_ACCESS_DENIED. _launch_detached_restart_command let that PermissionError escape, so the restart helper never launched: the gateway then stopped for the planned restart and never came back. Retry the watcher spawn without the breakaway flag, the same fallback gateway_windows._spawn_detached already uses.
Collaborator
Contributor
|
Thanks for the focused Windows restart fix. This is now redundant with the earlier duplicate implementation.
Closing as implemented on main. |
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
On Windows, when the gateway runs inside a job object that disallows breakaway (no
JOB_OBJECT_LIMIT_BREAKAWAY_OK— e.g. when started via Task Scheduler),CreateProcesswithCREATE_BREAKAWAY_FROM_JOBfails withERROR_ACCESS_DENIED, which Python surfaces asPermissionError.GatewayRunner._launch_detached_restart_commandlets that exception escape. The caller inrequest_restartonly logs it (Failed to launch detached gateway restart helper: [WinError 5] Access is denied) and then proceeds withstop(restart=True)anyway — so the gateway shuts down for the planned restart and never comes back until someone starts it manually.This is reproducible in the wild: a messaging-platform plugin auto-update triggers a detached restart, the helper launch fails with WinError 5, and the gateway stays dead for days (the Task Scheduler entry only triggers at logon).
Fix
Retry the watcher spawn without
CREATE_BREAKAWAY_FROM_JOBwhen the firstPopenraisesOSError— the exact fallbackgateway_windows._spawn_detachedalready implements for the same documented condition, and the patternwindows_detach_flags_without_breakaway()was added for. Without the breakaway flag the watcher stays inside the job, which is still far better than no watcher at all.Testing
test_windows_detached_restart_retries_without_breakaway: first spawn raisesPermissionError(5), asserts a second spawn happens with the no-breakaway flags and identical argv.pytest tests/gateway/test_restart_drain.py— 25 passed.