Move shutdown_worker RPC to initiate_shutdown#1197
Open
yuandrew wants to merge 12 commits intotemporalio:masterfrom
Open
Move shutdown_worker RPC to initiate_shutdown#1197yuandrew wants to merge 12 commits intotemporalio:masterfrom
yuandrew wants to merge 12 commits intotemporalio:masterfrom
Conversation
Sushisource
reviewed
Apr 3, 2026
Comment on lines
-539
to
-540
| assert_eq!(workflow_task_slots.current_available_slots, 5); | ||
| assert_eq!(workflow_task_slots.current_used_slots, 1); |
Contributor
Author
There was a problem hiding this comment.
With the new shutdown flow taking a little longer, these checks aren't deterministic. These checks are technically all checked in in_activity_checks, kept the assert_eq!(workflow_task_slots.total_processed_tasks, 2); check, which is unique to the shutdown case
…me timeout to avoid race
Sushisource
reviewed
Apr 3, 2026
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 522a529. Configure here.
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.

What was changed
Moved
shutdown_workerRPC toinitiate_shutdown, which requiresinitiate_shutdownto now be an async fnNOTE: also added a temp 5s timeout in order to avoid the race in temporalio/temporal#9545, will be safe to remove once the fix is fully deployed into cloud
Why?
shutdown_workerRPC needs to be sent at beginning of shutdown in order for server to know to send empty responses to pending polls.Checklist
Closes
How was this tested:
Added graceful_shutdown_sends_shutdown_worker_rpc_during_initiate to ensure RPC is sent at beginning of shutdown process
Note
Medium Risk
Touches core shutdown and polling behavior (including new timing-based timeouts), which can affect worker liveness and graceful termination under load. Changes are well-covered by new regression tests but still carry concurrency/race risk.
Overview
Fixes graceful worker shutdown so in-flight long polls can be drained without deadlocking.
ShutdownWorkerRPC is now spawned duringWorker::initiate_shutdown(stored and awaited inWorker::shutdown), and poll streams treat empty responses after shutdown as a termination signal rather than a normal poll timeout/retry. Adds a temporary 5s interrupt window for graceful polls to avoid a known server race (temporalio/temporal#9545), and increases the all-permits shutdown watchdog to 6s to match.Adds targeted unit/integration tests covering: RPC sent during initiate, poll stream termination on empty-after-shutdown, permits timeout alignment, and the race scenario; adjusts heartbeat integration assertions to wait for shutdown state.
Reviewed by Cursor Bugbot for commit 5863db7. Bugbot is set up for automated code reviews on this repo. Configure here.