Skip to content

resync cancellation robustness: dispatch deadlock, walker leak, and per-bucket cancel routing #137

Closed

Description

@Vonng

Tracks the inherited resync-cancellation defects deliberately left out of #136, which was scoped to counter integrity (persisted terminal counts must be complete and must not report Completed when work was dropped). These are all pre-existing on the fork baseline (e7d0e62f1) and are orthogonal to #136's counter fix; a full-lifecycle adversarial review of resyncBucket surfaced them. Analogous to how #133 tracks the multi-pool concern deferred from #120.

Decision record (maintainer ruling: narrow #136 + this follow-up; joint analysis by the maintainer and the Codex reviewer): the counter-integrity fix ships in #136; the cancellation architecture is fixed here.

Defects (all inherited from baseline)

  1. Dispatch deadlock on cancellation. cmd/bucket-replication.go — the object dispatch workers[h%uint64(resyncParallelRoutines)] <- roi is a blocking send inside a default case, outside cancellation. A full worker queue (100) plus cancellation (that worker exits, nobody drains its queue) wedges the dispatcher forever; the resync slot and result consumer never release.

  2. Abandoned walker goroutine on early return. objectAPI.Walk(ctx, ...) is passed the parent context and never cancelled when resyncBucket returns early. The walker blocks feeding objInfoCh (see cmd/erasure-server-pool.go Walk send) and, because normal resync runs under GlobalContext, can survive until server shutdown.

  3. One unkeyed cancel token cannot stop N concurrent bucket resyncs. cmd/site-replication.go cancelSiteResync sets every matching bucket's status to ResyncCanceled but sends a single unkeyed token to the shared resyncCancelCh (buffer resyncWorkerCnt). The pool permits up to 10 concurrent bucket resyncs; only one bucket's dispatcher/worker consumes the token, an unrelated concurrent run can consume it, and a buffered leftover token can affect a later run. A continuing bucket's finalizer can also overwrite its API-assigned Canceled with Completed, breaking site/bucket status agreement.

  4. Worker token-stealing / cancellation not observed during blocking phases. Both worker selects read resyncCancelCh, competing for the single token with the dispatcher; and the dispatcher cannot observe cancellation while blocked on a bare objInfoCh receive or (with the counter finish() drain) while joining workers.

Suggested direction

Give this bucket's resync an owned context.WithCancel derived from the parent that the walker, dispatcher, and workers all observe (a cancel becomes a broadcast); make the dispatch send a cancellable select case; route cancellation by resyncID so cancelSiteResync reaches every matching bucket's context; and reconcile site vs bucket terminal status so a cancelled run cannot later persist Completed. A worktree prototype of much of this exists from the #136 round-3 exploration (dispatchResync, startResyncWalk, owned resyncCtx, token rewiring) and can seed the implementation — but it needs the per-resyncID pool-level routing (item 3) which #136's single-bucket work did not cover, and its own adversarial review.

Acceptance criteria

  • Cancellation during a bare walk receive and during worker finalization is observed (no readerless interval).
  • A full worker queue plus cancellation cannot deadlock the dispatcher; the resync slot and consumer always release.
  • Walk runs under an owned context cancelled on every resyncBucket exit; no walker goroutine leak.
  • cancelSiteResync reliably stops every matching bucket resync (routing keyed by resync ID), with no cross-run token consumption and no stale buffered token affecting a later run.
  • Site-level and per-bucket terminal status stay consistent under cancellation (a cancelled run never later persists Completed).
  • Deterministic (testing/synctest) regressions for each of the above.

Non-goals

Activity

  1. moved this from Backlog to In progress in Siloon Sep 9, 2026
  2. moved this from In progress to Done in Siloon Sep 9, 2026
  3. Vonng commented on Sep 15, 2026

    @Vonng
    MemberAuthor

    This was resolved in PR #162, merged as d1105bbb.

    Each resync run now owns a cancelable context. Cancellation targets the resync ID and reaches both active and queued runs, including a walker or dispatcher blocked on work. Registration and finalization protect against canceled or stale runs overwriting newer state, and resumed runs retain their leader context until they finish. Successful runs still drain their final results before persisting terminal counters, preserving the accounting fix from #136.

    The merged change includes race-tested regressions for cancellation, blocked dispatch, terminal-state races and recovery. The resync lifecycle documentation explains the implementation and its concurrency boundaries.

    Availability: this fix is on main, but is not included in Server RELEASE.2026-09-03T13-18-01Z, still the latest published Server as of September 16. See the component and release matrix; final release acceptance is tracked in #203.

  4. added
    bug
    on Sep 15, 2026
  5. self-assigned this
    on Sep 15, 2026
  6. added theissue type on Sep 15, 2026
  7. added this to the 20260916 milestone on Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

Projects

  • Status
    Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions