Skip to content

Commit 7e4ada4

Browse files
fix(spider-scheduler): Cancel the runtime when the scheduler core exits on error. (#391)
1 parent 6d36c43 commit 7e4ada4

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

components/spider-scheduler/src/core.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ pub trait SchedulerCore: Send {
5555
/// and writes assignments to `sink`, repeating until `cancellation_token` is fired, at which
5656
/// point it returns.
5757
///
58+
/// The implementation does not need to fire the cancellation token when exiting on error: this
59+
/// cancellation is handled by the runtime.
60+
///
5861
/// # Parameters
5962
///
6063
/// * `storage_client` - The storage client used to poll the inbound queue and read state for

components/spider-scheduler/src/runtime.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,24 @@ pub async fn create_runtime<SchedulerStorageClientType: SchedulerStorageClient +
148148
let service = SchedulerServiceState::new(dispatch_queue_reader, registry, scheduler_id);
149149
let core = scheduler_config.make_core::<SchedulerStorageClientType, DispatchQueueWriter>();
150150

151-
let core_join_handle = tokio::spawn(core.run(
152-
storage_client,
153-
dispatch_queue_writer,
154-
TaskAssignmentIdIssuer::new(),
155-
cancellation_token.clone(),
156-
));
151+
let core_cancellation_token = cancellation_token.clone();
152+
let core_join_handle = tokio::spawn(async move {
153+
core.run(
154+
storage_client,
155+
dispatch_queue_writer,
156+
TaskAssignmentIdIssuer::new(),
157+
core_cancellation_token.clone(),
158+
)
159+
.await
160+
.inspect_err(|e| {
161+
tracing::error!(
162+
scheduler_id = % scheduler_id,
163+
error = % e,
164+
"Scheduler core exited on error. Cancelling runtime."
165+
);
166+
core_cancellation_token.cancel();
167+
})
168+
});
157169

158170
let runtime = Runtime {
159171
core_join_handle,

0 commit comments

Comments
 (0)