-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix: scope KV router cancellation to router lifetime #10730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,12 +87,15 @@ impl WorkerQueryClient { | |
| /// The background loop watches `ComponentEndpoints` discovery for query endpoints, | ||
| /// recovers each `(worker_id, dp_rank)` as it appears, and sends worker removal | ||
| /// events when all dp_ranks for a worker disappear. | ||
| pub async fn spawn(component: Component, indexer: Indexer) -> Result<Arc<Self>> { | ||
| pub async fn spawn( | ||
| component: Component, | ||
| indexer: Indexer, | ||
| cancel_token: tokio_util::sync::CancellationToken, | ||
| ) -> Result<Arc<Self>> { | ||
| let transport = Arc::new(RuntimeWorkerQueryTransport::new(&component).await?); | ||
| let client = Self::new(component.clone(), indexer, transport); | ||
|
|
||
| let client_bg = client.clone(); | ||
| let cancel_token = component.drt().primary_token(); | ||
| tokio::spawn(async move { | ||
| if let Err(e) = client_bg.run_discovery_loop(cancel_token).await { | ||
|
Comment on lines
+90
to
100
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Store the cancellation token and apply it to recovery tasks too. The new token only stops the discovery loop. Recovery tasks spawned by Direction for the fix pub struct WorkerQueryClient {
component: Component,
transport: Arc<dyn WorkerQueryTransport>,
/// Indexer for applying recovered events and worker removals.
indexer: Indexer,
+ cancel_token: tokio_util::sync::CancellationToken,
worker_states: DashMap<WorkerId, Arc<Mutex<WorkerState>>>,
query_endpoints: WorkerQueryEndpointDirectory,
recovery_semaphore: Arc<Semaphore>,
}Then pass the token through Also applies to: 358-384, 531-590 🤖 Prompt for AI Agents |
||
| tracing::error!("WorkerQueryClient discovery loop failed: {e}"); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Runtime::child_token()is tied to the endpoint-shutdown token (lib/runtime/src/runtime.rs:293-295), and shutdown cancels that in Phase 1 before waiting for graceful endpoints (lib/runtime/src/runtime.rs:322-338). Because this router token is now passed into the KV indexer/subscriber paths, single-thread KV routers (router_event_threads=1) can stop theirKvIndexerduring the graceful-drain window and make in-flight requests hitIndexerOffline; the previousprimary_token()stayed alive until Phase 3. Use a router-owned child of the primary token, while still canceling it inDrop.Useful? React with 👍 / 👎.