Skip to content

pool: the archive sweep marks a claim when its archive starts, not when the sweep picks it - #679

Merged
CMGS merged 1 commit into
mainfrom
archive-mark
Dec 1, 2026
Merged

CMGS merged 1 commit into
mainfrom
archive-mark

Conversation

@CMGS

@CMGS CMGS commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Found by the review round on main after #677 and #678. The bug is older than that work and is in v0.1.38.

What was wrong

archiveOnce picks every hibernated claim that is idle past archive_after and set m.archiving for each one at the pick. The archives then run on a bounded set of workers, each one a snapshot export and an upload, so a claim late in a batch carried the mark for as long as the batch took, although no archive of it had started.

Every reader of the mark takes it to mean "an archive of this claim is running", and a wake does not look at it. So a claim that its owner woke while it waited in the queue was running, and until its worker came up:

  • POST /renew answered 409 sandbox is archived; a wake or an exec wakes it first;
  • the liveness pass and replication skipped it;
  • a move and an evacuation refused it.

A wake renews the lease only when it has already lapsed. If the lease ended inside that wait and on_expire was not archive, the reap destroyed a running claim whose owner had asked to renew in time.

A batch gets long when many claims hibernate together, when archive_after is turned on for a pool that already holds hibernated claims, and when archives retry together after a store outage.

The fix

The sweep marks a claim when its archive starts. The worker takes m.mu, checks that it still holds the record and that the claim is still due (archiveDueLocked, the pick's own predicate), and only then marks it and calls archive. A claim that woke, that the reap archived at its lease end, or that a resize replaced while it waited is skipped with no log, as errWokeMeanwhile was.

archive is unchanged: the reap and the evacuation still mark before they call it. A reap that takes a queued claim now archives it itself, and the queued worker finds the mark or the checkpoint and skips. Two archive sweeps cannot overlap (m.sweeps.archive).

A renew considered and rejected: letting Renew through whenever the marked claim has no snapshot. The reap marks a running claim at its deadline before it pauses and archives it; a renew let through there would answer 200 and then lose its lease to the archive's retention deadline.

Test

TestAClaimWokenWhileItWaitsForItsArchiveRenews: two due claims, one maintenance slot, the first archive held inside the store's publish; the second claim carries no mark, wakes and renews; after the release the first is archived and the second runs. On the old archive.go it fails 3 of 3:

archive_test.go:1016: sb_… carries the archive mark while it waits for its archive
archive_test.go:1025: renew the woken claim: sandbox is archived; a wake or an exec wakes it first, want nil

On the fix it passes with -race -count=20.

TestRemovedTenantsClaimIsNeitherArchivedNorWokenNorForked read m.archiving right after archiveOnce; with the mark set later that check would pass without testing anything, so it now waits for the sweep to finish before it reads.

Cost

Nothing on the claim path. Per archived claim: one more m.mu section and one more evaluation of the due predicate in the worker. The pick no longer writes the map.

Gates

golangci-lint 10 × 0 issues. (5 modules × darwin, linux), asl and fmt clean, comments +0 −1 in archive.go, race tests green on darwin and in a Linux container. Production +19 −12, tests +52.

Not run on hardware: the change is one decision under m.mu, and a cell would need uploads slow enough to hold a queue. The unit test holds the store instead.

…en the sweep picks it

archiveOnce set m.archiving for every victim at the pick, but the archives run on a bounded
set of workers, each one an export and an upload, so a victim late in a batch carried the
mark for as long as the batch took. Every reader of the mark takes it to mean that an archive
of the claim is running. A wake does not look at it, so a claim its owner woke while it waited
in the queue was running and still got a 409 "sandbox is archived" on renew, was skipped by
the liveness and replication passes, and was refused a move or an evacuation until its worker
came up. If its lease ended in that wait and on_expire was not archive, the reap destroyed a
running claim whose owner had asked to renew in time.

The worker now checks under m.mu that it still holds the record and that the claim is still
due, and only then marks it and archives it. A claim that woke, was archived by the reap or
was replaced while it waited is skipped. The bug predates the pool cleanup and is in v0.1.38.
@CMGS
CMGS merged commit 727e923 into main Dec 1, 2026
1 check passed
CMGS added a commit that referenced this pull request Dec 1, 2026
…e refuses a resize into a replicating pool (#684)

Docs for behaviour that PRs merged since v0.1.38 changed: egress.md states that an origin's early answer or the proxy's own 502 or 429, sent before the guest's request body was read to its end, carries Connection: close, arrives whole, and ends that guest connection (#681); cluster.md states the resize refusal on a node whose lease is overdue and that a claim resized into its policy pool is replicated from then on (#676), and that the hourly row settling leaves a claim a transition holds to the next pass (#674); CHECKLIST.md states the archive sweep worker's check before it marks a claim (#679); deploy.md states that a preview URL can show a truncated reply when the guest app answers before it read the whole request body.
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.

1 participant