Repository navigation
metadata: bound each snapshot GC pass with a single timeout - #14026
NahumLitvin wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR prevents snapshot garbage collection from indefinitely holding the metadata snapshotter write lock when a proxy snapshotter stalls during Snapshotter.Walk, by adding a GC-scoped timeout for the walk phase (mirroring the earlier bounded Remove work in #13799).
Changes:
- Add a new timeout key (
io.containerd.timeout.gc.snapshotter.walk, default30m) and apply it to the GC-path snapshot tree walk. - Ensure a timed-out walk fails the GC pass before any pruning and skips the deferred unbounded
Cleanup. - Add a synctest regression test verifying a hung
Walktriggers zeroRemoveand zeroCleanup, and document the new timeout key.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| docs/man/containerd-config.toml.5.md | Documents the new GC snapshotter walk timeout key in the timeouts section. |
| core/metadata/snapshot.go | Introduces and wires a GC-specific Walk timeout via pkg/timeout.WithContext in walkTree. |
| core/metadata/snapshot_test.go | Adds a synctest regression test covering hung Walk behavior (no prune/cleanup on timeout). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| _, err := msn.garbageCollect(ctx) | ||
| if !errors.Is(err, context.DeadlineExceeded) { | ||
| t.Fatalf("expected the bounded Walk to fail with DeadlineExceeded, got %v", err) | ||
| } |
5a09d09 to
69b6f52
Compare
69b6f52 to
891cbfe
Compare
mikebrow
left a comment
There was a problem hiding this comment.
alternative for consideration:
sounds like we wanted both the walkTree and each recursive pruneBranch to be included in one timeout..
let's create the ctx with timeout and defer the cancel in the higher level garbageCollect func before calling both the walkTree and the pruneBranch.. methods thus having one timeout for all storage bound funcs in the gc while under the lock.
|
see slack thread.. Derek postulates resolving why the snapshotter (via proxy layer?) isn't quickly reporting the snapshotter is offline.. vs using timeouts closer to the client(s) and gc scheduler |
891cbfe to
08796a7
Compare
| // gcSnapshotterTimeoutKey bounds one full snapshot garbage collection pass, | ||
| // which holds the snapshotter write lock across every snapshotter call it | ||
| // makes (Walk, each Remove, and the final Cleanup): an unresponsive | ||
| // snapshotter (e.g. a hung proxy plugin RPC) would otherwise block all | ||
| // snapshot operations forever. On timeout the rest of the pass is abandoned; | ||
| // remaining snapshots stay orphaned and are retried on the next GC pass. | ||
| // snapshot operations forever. On timeout the pass is abandoned; remaining | ||
| // snapshots stay orphaned and are retried on the next GC pass. |
There was a problem hiding this comment.
reworded, the lock is released before Cleanup runs, the comment now says which parts run under the lock and which are only under the shared deadline.
|
done, moved the context up to garbageCollect as you suggested, and per @fuweid's comment it's now one |
| // garbageCollect removes all snapshots that are no longer used. | ||
| func (s *snapshotter) garbageCollect(ctx context.Context) (d time.Duration, err error) { | ||
| s.l.Lock() | ||
| gcCtx, cancel := timeout.WithContext(ctx, gcSnapshotterTimeoutKey) |
There was a problem hiding this comment.
thought: maybe this new context and defer should happen before the lock is requested
There was a problem hiding this comment.
done, the context now starts before the lock, so time spent waiting on a lock held by a stuck pass counts against the same deadline.
08796a7 to
6c675c0
Compare
|
Hi @NahumLitvin and @mikebrow , after revisited the GC component and the discussion in slack, I am thinking that we should move the timeout into proxy client layer, like |
|
makes sense to me, and it is the better home. a proxy snapshotter can hang on any of its calls, so a timeout in the client covers all 10 methods at once instead of one component at a time. on sizing: id do it as a separate PR, not a rewrite of this one: different package, and this one is already approved by mikebrow. one open question for the GC path though. the client default only applies when there is no deadline yet, and with this PR merged the GC pass always sets its own 30m. so: merge this one and let the client default cover everything else, or close it and go straight to the client layer? |
|
also #14010 is relevant here. it lists the daemon calls into a proxy plugin that run under a shared lock. snapshot GC Walk (what this PR bounds) and content GC Walk/Delete have no limit at all, the rest stop when their request deadline does. so a default_timeout in the client would cover that whole list at once, instead of a PR per component in content, metadata and the bolt paths. that route is what produced #13799 and this PR. |
Snapshot GC holds the snapshotter write lock across every snapshotter call it makes: Walk to build the tree, each Remove while pruning, and the final Cleanup. Only Remove was bounded (io.containerd.timeout.gc. snapshotter.remove); a proxy snapshotter that wedges in Walk or Cleanup still holds the lock forever and no new container can start. Replace the per-call Remove timeout with one io.containerd.timeout.gc. snapshotter key (default 30m) applied to the whole pass in garbageCollect, covering Walk, Remove, and Cleanup under one deadline. The removed key never shipped in a release, so no deprecation is needed. On timeout the pass is abandoned before any further pruning; orphans are retried on the next pass. Signed-off-by: Nahum Litvin <[email protected]>
fece3d3 to
b5e8be1
Compare
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped to snapshot GC timeout semantics, removes the unbounded Walk/Cleanup gap described in the issue, and is backed by targeted synctest regressions.
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 0 new
- Review effort level: Lite
There was a problem hiding this comment.
🟢 Approval recommended
The timeout is applied consistently across the full GC pass, the obsolete key is fully removed, and targeted synctest regressions cover the key failure modes (hanging Walk/Remove).
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 0 new
- Review effort level: Lite
|
before i write it: #14016 and #14025 cover the content store side of the same list, so a client default probably replaces all three of these, not only this one. say the word and il close them. design question too. content Writer lives past the call that made it, and Walk streams, so a deadline on each call would cut a long ingest. leave Writer out of it, or give it a key of its own? tell me which and il send it for both proxy clients, with an opt on the constructor so client.go keeps working. |
Two things to consider:
|
I understand the concern. Currently, each GC cycle has two phases.
containerd/core/metadata/db.go Lines 449 to 486 in fb6dc53 Snapshot cleanup does hold a snapshotter-level lock while calling This is why I proposed an optional default timeout at the proxy snapshotter client boundary. It ensures that a single stuck Walk, Remove, or other proxy RPC cannot hold the snapshotter-level lock indefinitely, not just in GC cycle. |
ah.. I see your reasoning now. Thanks! SGTM! |
|
Since we are going to release 2.4, we need to address that or revert the timeout setting |
nod.. #14119 |
|
PR needs rebase. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
The content garbage collector holds the content store write lock while calling the backend Store.Walk, Store.Delete and Store.Abort. cleanupContent also detaches cancellation (context.WithoutCancel), so a backend call that never returns - e.g. a proxy content store whose RPC connection has wedged - holds the write lock forever. Every subsequent content operation then blocks behind the lock, including pull ingest, until the plugin recovers on its own. This is the content-side twin of the snapshot GC pass bounded by containerd#14026. Follow the design agreed there (a single timeout for the whole pass instead of per-call keys): io.containerd.timeout.gc.content (default 30m, operator-tunable through config.toml like the other timeout keys) is created at the top of garbageCollect and covers the Walk/Delete sweep and the ingest Abort sweep under one deadline. On timeout the pass fails, and the blobs and ingests left behind stay orphaned for the next pass. Signed-off-by: chansuke <[email protected]>
Problem
Snapshot GC holds the snapshotter write lock across every snapshotter call it makes:
Walkto build the tree, eachRemovewhile pruning, and the finalCleanup. OnlyRemovewas bounded (#13799); a proxy snapshotter that wedges inWalkorCleanupstill holds the lock forever and no new container can start.Walkruns first in the pass, so the boundedRemovepath is never even reached. Called out as a known gap in #13799.Fix
One timeout for the whole GC pass, per review feedback from @mikebrow (move the context up to
garbageCollect) and @fuweid (a single timeout instead of per-call keys):io.containerd.timeout.gc.snapshotter(default 30m) created ingarbageCollect, coveringWalk, everyRemove, andCleanupunder one deadline. The per-callio.containerd.timeout.gc.snapshotter.removekey from #13799 is removed; it never shipped in a release, so no deprecation is needed.On timeout the pass fails before any further pruning, so a partial walk result is never used to remove snapshots; the next pass retries.
The synctest regression tests assert a timed-out
Walktriggers zeroRemoveand zeroCleanupcalls, and that a timed-outRemoveabandons the pass, deadlocking in under a second if the bound is removed.Refs #13798.