spacedriveapp/spacedrive · error
Worker channel closed trying to force task abortion
Error message
Worker channel closed trying to force task abortion
What it means
Worker::force_task_abortion sends a ForceAbortion message over the worker's command channel and panics with .expect() when the channel is closed, i.e. the worker's message-processing task has exited and dropped its receiver. It means a force-abort was directed at a worker that has already shut down, so the request can never be acknowledged.
Source
Thrown at crates/task-system/src/worker/mod.rs:178
&self,
task_id: TaskId,
ack: oneshot::Sender<Result<(), SystemError>>,
) {
self.msgs_tx
.send(WorkerMessage::CancelNotRunningTask { task_id, ack })
.await
.expect("Worker channel closed trying to cancel a not running task");
}
pub async fn force_task_abortion(
&self,
task_id: TaskId,
ack: oneshot::Sender<Result<(), SystemError>>,
) {
self.msgs_tx
.send(WorkerMessage::ForceAbortion { task_id, ack })
.await
.expect("Worker channel closed trying to force task abortion");
}
#[instrument(skip(self), fields(worker_id = self.id))]
pub async fn shutdown(&self) {
if let Some(handle) = self
.handle
.try_borrow_mut()
.ok()
.and_then(|mut maybe_handle| maybe_handle.take())
{
let (tx, rx) = oneshot::channel();
self.msgs_tx
.send(WorkerMessage::ShutdownRequest(tx))
.await
.expect("Worker channel closed trying to shutdown");
rx.await.expect("Worker channel closed trying to shutdown");View on GitHub (pinned to 6dfeccf211)
Solutions
- Sequence force-aborts before shutdown begins, and await them (the ack oneshot) before calling system.shutdown()
- Library-level fix: map SendError to a SystemError (e.g. worker-unavailable) or warn-and-return instead of .expect, since shutdown already force-finalizes all tasks the worker owned
- Ensure your tasks honor interrupt signals (Interrupter/worktable) so force-abort acks return quickly and don't overlap the shutdown window
- As a last-resort containment, call force-abort through AssertUnwindSafe(..).catch_unwind() and interpret a panic as 'worker gone, nothing to abort'
Example fix
// before (worker/mod.rs:175-178)
self.msgs_tx
.send(WorkerMessage::ForceAbortion { task_id, ack })
.await
.expect("Worker channel closed trying to force task abortion");
// after
if self
.msgs_tx
.send(WorkerMessage::ForceAbortion { task_id, ack })
.await
.is_err()
{
warn!(%task_id, worker_id = self.id, "Worker channel closed; force abortion request dropped (worker already shutdown)");
} Defensive patterns
Strategy: validation
Validate before calling
use std::sync::atomic::{AtomicBool, Ordering};
static SHUTTING_DOWN: AtomicBool = AtomicBool::new(false);
fn can_force_abort() -> bool { !SHUTTING_DOWN.load(Ordering::Acquire) }
// Force-abort is await-heavy on the worker side (run.rs:79-88); complete it
// BEFORE shutdown begins, otherwise skip it and let shutdown finalize the task. Try / catch
use futures::FutureExt;
use std::panic::AssertUnwindSafe;
if AssertUnwindSafe(remote.force_abort()).catch_unwind().await.is_err() {
// Worker already down; its shutdown path force-finalizes every task it owned
// (send_forced_abortion_task_response, runner.rs:1385-1400).
} Prevention
- Design tasks to honor the Interrupter/worktable interrupt signals so force-abort is rarely needed during teardown
- Never overlap force-abort with system.shutdown(); sequence them and await the ack in between
- Treat force-abort-after-shutdown as a no-op by contract, since shutdown already finalizes all tasks
When it happens
Trigger: The dispatch chain system.rs:396/408 -> Worker::force_task_abortion (worker/mod.rs:170) firing after the target worker's run loop returned from ShutdownRequest handling (run.rs:90-92), or while the runtime is being torn down and the worker task is dropped. Note force_task_abortion is await-heavy on the worker side (run.rs:79-88 awaits runner.force_task_abortion), so a worker blocked there while the system shuts down increases the race window.
Common situations: Force-aborting stuck tasks exactly during shutdown (the most common time to force-abort); watchdog code that aborts tasks on a timer firing concurrently with teardown; tests that force-abort then immediately shutdown the system without awaiting in between.
Related errors
- Worker channel closed trying to pause a not running task
- Worker channel closed trying to cancel a not running task
- Worker channel closed trying to steal task
- Worker channel closed trying to shutdown
- System channel closed trying to report working
AI-assisted analysis of spacedriveapp/spacedrive@6dfeccf211 (2026-08-16).
Data as JSON: /api/errors/4570441bf62c70fa.
Report an issue: GitHub.