Skip to content

Don't hang worker shutdown when worker validation fails - #2023

Open
parbhatkapila4 wants to merge 1 commit into
temporalio:mainfrom
parbhatkapila4:fix/worker-validate-shutdown-hang
Open

parbhatkapila4 wants to merge 1 commit into
temporalio:mainfrom
parbhatkapila4:fix/worker-validate-shutdown-hang

Conversation

@parbhatkapila4

Copy link
Copy Markdown
Contributor

If Worker.run() fails validation, for example because the namespace doesn't exist, _run() raises before it gets to the shutdown steps, so _shutdown_complete_event is never set. Calling shutdown() after that waits forever, even though the run() docstring says it's harmless to call. async with Worker(...) hits the same thing: the worker cancels the block to report the error, aexit calls shutdown(), and it hangs instead of raising the validation error. So a typo in the namespace freezes the app with no error.

Now a failed validation marks shutdown complete before re-raising, as long as the worker hadn't already started. shutdown() returns right away, and async with raises "Worker validation failed".

Added a test next to test_worker_validate_fail that covers both shutdown() after a failed run() and async with. On main, shutdown() doesn't finish within 10 seconds. With the fix, it passes.

@parbhatkapila4
parbhatkapila4 requested a review from a team as a code owner October 26, 2026 19:21

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