Skip to content

Fix graceful shutdown of the shared worker-command poller - #3235

Open
yuandrew wants to merge 4 commits into
mainfrom
yuandrew/graceful-command-poll-shutdown
Open

yuandrew wants to merge 4 commits into
mainfrom
yuandrew/graceful-command-poll-shutdown

Conversation

@yuandrew

@yuandrew yuandrew commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What changed?

Keep the shared worker-command poller running while the factory's regular workers drain. On namespaces that support graceful poll completion, send ShutdownWorker for the command queue so the server can complete the outstanding Nexus poll. shutdownNow() and namespaces without the capability still interrupt the poll.

Why?

Activities can still receive worker commands during the drain. The Go SDK fixed the same shutdown issue in temporalio/sdk-go#2907.

Testing

Added an in-process gRPC regression test that holds an activity open, observes a second command poll during shutdown, verifies the shutdown request targets that poll, and checks that the factory terminates without interrupting it.

The focused Java shutdown suite passed 35 tests. Three tests that require an external Temporal server were skipped.

Compatibility

Uses the existing ShutdownWorker RPC. No public API changes or companion server PR.

Closes #3234.


Note

Medium Risk
Changes worker factory shutdown ordering and Nexus poll teardown; incorrect behavior could block command delivery during drain or leave polls stuck, though graceful paths are gated on namespace capability and RPC failure falls back to interrupt.

Overview
Fixes graceful WorkerFactory.shutdown() so the shared worker-command Nexus poller stays up while regular workers drain activities, instead of being torn down immediately.

When the namespace supports graceful poll completion, WorkerFactory defers stopping the command worker until other workers finish; NexusWorker sends ShutdownWorker for the command queue (with a per-factory random workerInstanceKey so instances shut down independently) and only falls back to interrupting the poll if that RPC fails. ShutdownManager now exposes whether the shutdown RPC succeeded.

Adds in-process regression tests and a CHANGELOG fix note.

Reviewed by Cursor Bugbot for commit 24bf67e. Bugbot is set up for automated code reviews on this repo. Configure here.

Keep the shared command poller available while regular workers drain.
On supported namespaces, ask the server to complete the outstanding
poll so graceful shutdown can finish without interrupting it.
Keep both changelog entries after main added the workflow poller
balancing fix.
Give each command poller a distinct instance key so shutting down one
factory does not suppress polls from another factory on the same client.
Use the RPC outcome to fall back to interrupting the command poll.
This lets factory shutdown proceed without waiting for the long poll
to expire when the server cannot complete it.
@yuandrew
yuandrew marked this pull request as ready for review November 24, 2026 22:18
@yuandrew
yuandrew requested a review from a team as a code owner November 24, 2026 22:18

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.

Fix graceful shutdown of the shared worker-command poller

1 participant