Skip to content

fix(nzb-dispatch): bound worker shutdown to one shared deadline (ported from fork) - #147

Merged
thedancingdeveloper merged 1 commit into
mainfrom
fix/bounded-worker-shutdown
Sep 27, 2026
Merged

thedancingdeveloper merged 1 commit into
mainfrom
fix/bounded-worker-shutdown

Conversation

@thedancingdeveloper

Copy link
Copy Markdown
Collaborator

Summary

Ports ec279d7 from the MrVampy/rustnzb fork: a correctness fix for WorkerPool shutdown.

The bug (still present on main)

WorkerPool::shutdown gives each worker handle its own 10s tokio::time::timeout:

let timeout = Duration::from_secs(10);
for h in handles {
    let _ = tokio::time::timeout(timeout, h).await;
}

So worst-case shutdown time scales with worker count — N workers that all hang ⇒ up to N×10s before the pool gives up.

The fix

A single shared deadline via timeout_at, after which any still-running handles are aborted, bounding total shutdown to ~10s regardless of worker count:

async fn await_worker_shutdown(mut handles: Vec<JoinHandle<()>>, timeout: Duration) {
    let deadline = tokio::time::Instant::now() + timeout;
    for handle in &mut handles {
        if tokio::time::timeout_at(deadline, &mut *handle).await.is_err() { break; }
    }
    for handle in handles {
        if !handle.is_finished() { handle.abort(); }
    }
}

Tests

Ships a #[tokio::test(start_paused = true)] test, worker_shutdown_uses_one_shared_deadline, that spawns 3 never-completing workers and asserts the shutdown is still pending at 9s and completes once the single 10s deadline passes (proving it does not wait 3×10s).

  • cargo test -p nzb-dispatch → 42 passed
  • cargo clippy -p nzb-dispatch --all-targets, cargo fmt --check → clean

Applied cleanly onto main (pre-image matched byte-for-byte; JoinHandle already in scope).

Original author: @MrVampy (commit preserved via cherry-pick -x).

🤖 Generated with Claude Code

@thedancingdeveloper
thedancingdeveloper merged commit 81611c3 into main Sep 27, 2026
11 checks passed
@thedancingdeveloper
thedancingdeveloper deleted the fix/bounded-worker-shutdown branch September 27, 2026 11:12
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.

2 participants