Skip to content

[P2] Resync publishes Completed before the final object counters are persisted #136

Closed

Description

@Vonng

Independent verification update — 2026-09-06, round 2

The final-result drain/persistence acceptance below is verified on the integrated #138 candidate. Keep open until #138 merges. The latest head f8ca4a8656217165a78f3cea09a3c247d483e455 fixes the initial spelling-only lint failure; its product behavior is unchanged from tested 35d9f1824.

Healthy two-object resyncs report both objects and 8,917,248 ciphertext bytes in the first Completed response (~0.2 seconds), without waiting for the one-minute flush. A real quota-rejected missing-target upload reports 1 success / 1 failure immediately and preserves the exact status after source restart. The drain/producer ordering and cancellation-classification tests pass under the race detector.

Boundary: this verifies that every submitted result is persisted, not that every worker result is correctly classified. New #139 demonstrates a persistent false-success result when an existing destination replica rejects an update but still answers HEAD. That is an outcome-classification defect; #137 remains the cancellation follow-up. Do not treat Completed / zero failures as sufficient recovery acceptance until #139 is fixed.


Problem

replicate resync status can report Completed before the last object's counters are persisted. Immediately after a completed two-object resync it reports one object; the second appears only after the periodic one-minute flush. A last failed object can likewise be absent from the completed job's failure counters during this window.

This is separate from #120's inability to repair particular SSE-C replicas. It is an inherited resync-finalization defect in the result consumer / persisted status boundary; #134's HEAD marker does not fix it.

Reproduction

Independent review on 2026-09-06 using server main e7d0e62f16ed8a2373a4e9f5c4639d62886c09f2 plus #134 9e39aad802f0d5a674648fb439411568bc5296c0, and mcli main bec94e4ef47f63d978e57f19091506d2090bd6c6. Two real TLS servers, one server pool each, separate disposable data directories, bucket replication with proxying disabled. Both object versions were readable at source and destination before this control.

  1. Source bucket has exactly two object versions (single.txt and multipart.txt).
  2. Start mcli replicate resync start SOURCE/BUCKET --remote-bucket ARN.
  3. Read mcli --json replicate resync status SOURCE/BUCKET --remote-bucket ARN at 3, 33 and 65 seconds.

Observed for the same reset ID and completed timestamp:

Observation time Status replicationCount completedReplicationSize
3 seconds Completed 1 196704
33 seconds Completed 1 196704
65 seconds Completed 2 8917248

The object key in the saved result changes from single.txt to multipart.txt at the final observation. In the earlier damaged-replica test described in #120, the same timing window also exposed Completed with no reported failed object immediately after the sender had logged a failed transfer. This is not a claim that the counters remain wrong after the periodic flush.

Root cause

  • resyncBucket starts a separate goroutine that drains resultCh and calls incStats.
  • wg.Wait() waits for the object workers, not for that result-consumer goroutine.
  • The function sets resyncStatus = ResyncCompleted and returns. Deferred markStatus persists a completed snapshot before the last counter update necessarily runs.
  • incStats subsequently changes only in-memory state.
  • ResetBucketReplicationStatusHandler reads loadBucketResyncMetadata from disk, so it sees the incomplete final snapshot until PersistToDisk's resyncTimeInterval = time.Minute timer saves it.

These paths also exist in unchanged main. The runtime reproduction above used the integrated candidate; provenance on main was checked in source.

Minimal fix / acceptance

Drain/join the result consumer before persisting the final status. Preserve cancellation semantics and do not add polling or a fixed sleep.

  • A completed job's first persisted status includes every worker result, including the final failure.
  • A deterministic test delays the last incStats and verifies completion cannot be published ahead of it.
  • A two-object live resync immediately reports both objects, without waiting for the periodic flush.
  • A failed-object case preserves the failure count across restart after job completion.

P2: misleading recovery/accounting state, especially for automation that treats a completed job's zero failures as acceptance. No observed source-object data loss in this review.

Activity

  1. added
    bug
    on Sep 6, 2026
  2. moved this from Backlog to In progress in Siloon Sep 6, 2026
  3. Vonng commented on Sep 6, 2026

    @Vonng
    MemberAuthor

    Fix record — scoped to counter integrity; cancellation robustness → #137

    Disposition (maintainer ruling). Over three adversarial rounds the fix expanded from the filed counter-timing bug toward a full resync cancellation rewrite (reaching the site-replication per-bucket cancel token). The maintainer, with a joint trade-off analysis from the Codex reviewer, ruled to narrow #136 to counter integrity and track the inherited cancellation defects separately in #137 — the same pattern as #120→#133. Decision memo: the analysis compared narrow-plus-follow-up vs. fixing the whole cancellation architecture now, and both the maintainer and Codex converged on narrowing.

    Fix (PR #138, branch fix/issue-136-resync-counter-flush). Two counter-integrity problems:

    1. The result-consuming goroutine (incStats) was not joined before the deferred markStatus, so Completed could persist an under-count until the ~1m flush.
    2. A run could persist Completed even when work was dropped — parent context cancelled mid-drain, or a worker consuming the resync-cancel token and returning without submitting its computed result.

    Resolution: a resyncResults/finish() helper drains before persist (close worker inputs → join workers → close results → join consumer → persist; runs on every exit); and finalResyncStatus downgrades a tentative Completed to Failed when the parent context was cancelled or a worker aborted (recorded by sendResyncResult). The inherited cancellation mechanisms (Walk(ctx) inline, the default: blocking dispatch send, worker resyncCancelCh branches, site-replication.go) are deliberately unchanged and moved to #137.

    Adversarial review. Codex Astra 6 (Max) recommended exactly this minimal set for the narrowed scope, then reviewed the implementation: VERDICT PASS — ordering correct, parent-context recheck and worker-abort safeguard correct, helper extractions behavior-preserving, #137 mechanisms byte-identical with no residue.

    Local: gofmt/go vet/go build clean; -race clean; -run 'Resync' -count=1 passes; red-on-revert confirmed for each wait and downgrade term. Keeping this issue open until PR #138 is merged (CI on the pushed head).

  4. moved this from In progress to Done in Siloon Sep 6, 2026
  5. Vonng commented on Sep 7, 2026

    @Vonng
    MemberAuthor

    Resolved by #138 (merged to main as 8a1f594ad).

    resyncBucket no longer persists Completed before the final object counters are drained: resyncResults/finish() drain before persist, and finalResyncStatus downgrades Completed→Failed when the parent context errored or a worker aborted while draining. The cancellation architecture was intentionally left untouched.

    This is the narrowed scope selected as Option A; the broader cancellation-robustness work is tracked in #137.

    Verified: Codex adversarial review (narrowed PASS), deterministic red/green under testing/synctest, full acceptance on merged main.

  6. self-assigned this
    on Sep 15, 2026
  7. added theissue type on Sep 15, 2026
  8. 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