Repository navigation
fix(api): expire sandboxes and reclaim the files nothing references - #359
Merged
Merged
Conversation
tas50
force-pushed
the
fix/expire-sandboxes
branch
2 times, most recently
from
November 29, 2026 22:43
d221dd0 to
1d7a54f
Compare
A file uploaded through a sandbox stayed in the blob store forever unless a manifest that referenced it was later deleted or overwritten. Uncommitted sandboxes never expired, and no route lists or deletes blobs, so one org member could fill server memory (the default backend) or disk with files nothing used, and only deleting the org reclaimed them. A sandbox now expires two hours after it is created or, once committed, after the commit (twice the upload grant's lifetime, so a file cannot be uploaded after its sandbox stops protecting it). A running server sweeps every ten minutes: it deletes expired sandboxes and the files they announced that no cookbook or artifact manifest references and no open sandbox still names. Sandboxes stored without a timestamp by earlier versions count as expired. erchef keeps uncommitted sandboxes and their uploads indefinitely (bookshelf's cleanup only reaps uploads that never completed), so this is a deliberate difference, noted in the README. Signed-off-by: Tim Smith <tsmith84@proton.me>
A blob GC read which checksums were still referenced and then deleted the rest, with nothing ordering it against the handlers that check a blob exists and then record a dependence on it. A manifest PUT that passed its upload check and stored its manifest in between left the manifest referencing a deleted file, whose download URL then 404s. The sandbox sweep had the same gap, and also a sandbox announced after the sweep read the open sandboxes could be told a file needs no upload just before the sweep deleted it. The GC that overwriting or deleting a cookbook or artifact version runs had the same race already. Each org now has a blob-reference lock. createSandbox, commitSandbox and the cookbook and artifact PUTs hold it shared from their blob checks through the write that records the dependence; gcOrphanedBlobs and the sweep hold it exclusively from reading references through the deletes. A handler that runs a GC releases its shared hold first. File uploads take no lock, since the sweep never deletes a file an open sandbox names. Signed-off-by: Tim Smith <tsmith84@proton.me>
tas50
force-pushed
the
fix/expire-sandboxes
branch
from
November 29, 2026 22:45
1d7a54f to
18cd975
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A file uploaded through a sandbox stayed in the blob store until a manifest referencing it was deleted or overwritten. Uncommitted sandboxes never expired and no route lists or deletes blobs, so any org member with create on
sandboxescould fill server memory (memory backend) or disk (SQLite) with files nothing used. Only deleting the org got that space back.api.SweepSandboxesdeletes expired sandboxes and the files they announced that no cookbook/artifact manifest references and no open sandbox still names. The server runs it every ten minutes. Library users call it themselves.blobrefs.go).createSandbox,commitSandbox, cookbook PUT, artifact PUT.gcOrphanedBlobscall. This includes the existing GC on cookbook/artifact overwrite and delete, which had the same race on main.needs_upload: falsefor a file the sweep then deleted.erchef keeps uncommitted sandboxes and their uploads forever. Bookshelf's
bksw_cleanup_taskonly reaps uploads that never completed, and committed checksums are deleted only along with the cookbook/artifact version that referenced them. So this is a deliberate difference, noted in the README. The differential script does not commit sandboxes, so the baseline is unchanged.Unchanged: the sandbox and commit responses, the manifest checksum check, and which blobs GC on cookbook/artifact delete and overwrite removes. knife/chef upload, commit and PUT the manifest in one run.
Not addressed: no per-org quota (erchef has none). A member who keeps re-announcing a sandbox keeps its files alive, but removing that member from the org ends it within two hours.
Tests:
TestSandboxSweepCollectsUnreferencedUploads,TestSandboxSweepKeepsFilesOfOpenSandboxes,TestSandboxSweepCountsFromCommit(each on memory and SQLite),TestSandboxSweepReclaimsUntimedSandboxes,TestServerSweepsExpiredSandboxes.TestSandboxCreateDuringSweepKeepsTheBlob,TestManifestPutDuringSweepKeepsTheBlob,TestManifestPutDuringOverwriteGCKeepsTheBlob. All three failed before the lock.Overlap: #346 also edits
internal/api/cookbooks.go(getFile/blob reads; this PR touches the sandbox handlers, the cookbook PUT and the GC), and #347 editsserver/server.goandREADME.md. Any conflicts should be textual only. #353 adds per-org locks for group membership; this lock is separate from that one.