Skip to content

fix(worker): don't crash when stopping an exited worker on Windows - #718

Open
Wayfarer545 wants to merge 1 commit into
taskiq-python:masterfrom
Wayfarer545:fix/windows-shutdown-permission-error
Open

Wayfarer545 wants to merge 1 commit into
taskiq-python:masterfrom
Wayfarer545:fix/windows-shutdown-permission-error

Conversation

@Wayfarer545

Copy link
Copy Markdown

On Windows, Ctrl+C can crash the main process with PermissionError: [WinError 5] Access is denied and exit code 1.

The console delivers Ctrl+C to the workers too, so an idle worker has often exited by the time _shutdown_workers calls os.kill. On Windows os.kill means TerminateProcess, which fails this way for a process that has already exited. CPython handles the same case in Popen.terminate.

This change treats PermissionError like the existing ProcessLookupError branch.

Related to #422: same traceback, but the cause here isn't user permissions.

If several workers are running, the exception used to abort the loop, so workers after the exited one were left to finish their shutdown. Now they get os.kill too, as they already do when no worker has exited. On Windows that terminates them right away. That existing behavior is not changed here.

Tested on Windows 11, Python 3.13, with a real Ctrl+C in a new console (idle broker with 1 and 2 workers, ZeroMQBroker with tornado):

  • before: crash in 24 of 24 runs
  • after: exit code 0 and no traceback in 32 of 32 runs

The new test fails on Windows without the fix and passes with it on 3.10, 3.13 and 3.14. On Linux it passes either way, through the ProcessLookupError branch, so only the Windows CI job catches a regression.

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.

1 participant