Repository navigation
metadata: bound snapshotter Remove during garbage collection - #13799
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a bounded timeout for snapshot garbage-collection removals in core/metadata to prevent the snapshotter write lock from being held indefinitely when an underlying snapshotter Remove hangs (e.g., a wedged proxy snapshotter RPC).
Changes:
- Introduces a
pkg/timeoutkey (io.containerd.timeout.metadata.snapshot.remove, default 5m) and applies it toSnapshotter.Removecalls made during metadata snapshot GC. - Abandons the remainder of a GC pass after the first timed-out removal to avoid paying the timeout repeatedly for many orphans in a single cycle.
- Adds tests covering a hanging
Removeand the existingFailedPreconditiontolerance path.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| core/metadata/snapshot.go | Adds a GC-path Remove timeout and aborts the GC pass after the first timeout to prevent lock hold starvation. |
| core/metadata/snapshot_test.go | Adds regression tests for hanging Remove behavior and FailedPrecondition tolerance during GC. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
5e8e2da to
3b4ebc0
Compare
3b4ebc0 to
fb05a0e
Compare
|
Addressed the Copilot comments in fb05a0e:
Kept |
fb05a0e to
a0b3d39
Compare
|
Addressed the second review round in a0b3d39: reworded the test's Cleanup comment (the stub returns immediately; only real snapshotters hang), and documented |
a0b3d39 to
0e52a31
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (1)
core/metadata/snapshot.go:1019
removeTimedOutis only handled whenRemovereturns a non-nil error. If a snapshotter ignores the context deadline and eventually returnsnil,removeCtx.Err()will still beDeadlineExceededand this code will treat the operation as a success (and continue pruning / run Cleanup), even though it exceeded the configured bound. Consider treating a reached deadline as a timeout regardless ofRemove's returned error.
removeCtx, cancel := timeout.WithContext(ctx, snapshotRemoveTimeout)
err := s.Snapshotter.Remove(removeCtx, node.info.Name)
removeTimedOut := errors.Is(removeCtx.Err(), context.DeadlineExceeded)
cancel()
if err != nil {
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (1)
core/metadata/snapshot.go:57
- The PR description states the GC-bounded Remove uses timeout key
io.containerd.timeout.snapshot.removewith a default of 5m, but the implementation introducesio.containerd.timeout.gc.snapshotter.removewith a 30m default (and the manpage matches the code). Please reconcile this discrepancy (either update the PR description / docs to match the intended key+default, or adjust the code constants if the intended key/default are different).
// gcSnapshotterRemoveTimeoutKey bounds each Snapshotter.Remove during garbage
// collection, which holds the snapshotter write lock: 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.
const (
gcSnapshotterRemoveTimeoutKey = "io.containerd.timeout.gc.snapshotter.remove"
defaultGCSnapshotterRemoveTimeout = 30 * time.Minute
)
func init() {
timeout.Set(gcSnapshotterRemoveTimeoutKey, defaultGCSnapshotterRemoveTimeout)
}
The snapshot garbage collector holds the snapshotter write lock while calling the underlying Snapshotter.Remove. cleanupSnapshotter also detaches cancellation (context.WithoutCancel), so a Remove that never returns - e.g. a proxy snapshotter whose RPC connection has wedged - holds the write lock forever. Every subsequent snapshot operation on the node then blocks behind the lock, including CRI RunPodSandbox, turning the node into a permanent scheduling black hole while it still reports Ready. Observed in production with a proxy snapshotter (soci) that stopped answering after a file-descriptor exhaustion storm: the GC goroutine sat in WaitGroup.Wait for 4.5 hours with the Remove RPC parked in waitOnHeader, and 17 CRI operations queued behind the metadata lock. Bound each GC-path Remove with a timeout registered via pkg/timeout (io.containerd.timeout.gc.snapshotter.remove, default 30m, operator-tunable through config.toml like the other timeout keys). A timed-out Remove returns DeadlineExceeded, which is not a FailedPrecondition, so it propagates out of pruneBranch and ends the pass: a globally wedged snapshotter costs one timeout per GC cycle rather than one per orphaned snapshot, the deferred Cleanup is skipped because the pass failed, and the snapshots left behind stay orphaned for the next pass. Signed-off-by: Nahum Litvin <[email protected]>
b3740a1 to
a9d5caf
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (1)
core/metadata/snapshot.go:57
- The PR description states the timeout key is
io.containerd.timeout.snapshot.removewith a default of 5m, but the implementation (and the config manpage) introduceio.containerd.timeout.gc.snapshotter.removewith a 30m default. Please align the PR description and/or the key+default so users aren’t misled about how to configure this behavior.
// gcSnapshotterRemoveTimeoutKey bounds each Snapshotter.Remove during garbage
// collection, which holds the snapshotter write lock: 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.
const (
gcSnapshotterRemoveTimeoutKey = "io.containerd.timeout.gc.snapshotter.remove"
defaultGCSnapshotterRemoveTimeout = 30 * time.Minute
)
func init() {
timeout.Set(gcSnapshotterRemoveTimeoutKey, defaultGCSnapshotterRemoveTimeout)
}
The content garbage collector holds the content store write lock while calling the backend Store.Delete and Store.Abort. cleanupContent also detaches cancellation (context.WithoutCancel), so a Delete 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 snapshotter Remove hang bounded by containerd#13799. Bound each GC-path Delete and Abort with timeouts registered via pkg/timeout (io.containerd.timeout.gc.content.delete and io.containerd.timeout.gc.content.abort, default 30m, operator-tunable through config.toml like the other timeout keys). A timed-out call returns DeadlineExceeded, which propagates out of garbageCollect and ends the pass: a globally wedged content store costs one timeout per GC cycle rather than one per orphaned blob, and the blobs and ingests left behind stay orphaned for the next pass. Signed-off-by: chansuke <[email protected]>
The content garbage collector holds the content store write lock while calling the backend Store.Delete and Store.Abort. cleanupContent also detaches cancellation (context.WithoutCancel), so a Delete 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 snapshotter Remove hang bounded by containerd#13799. Bound each GC-path Delete and Abort with timeouts registered via pkg/timeout (io.containerd.timeout.gc.content.delete and io.containerd.timeout.gc.content.abort, default 30m, operator-tunable through config.toml like the other timeout keys). A timed-out call returns DeadlineExceeded, which propagates out of garbageCollect and ends the pass: a globally wedged content store costs one timeout per GC cycle rather than one per orphaned blob, and the blobs and ingests left behind stay orphaned for the next pass. Signed-off-by: chansuke <[email protected]>
Fixes #13798
Problem
During snapshot GC,
cleanupSnapshottercalls the snapshotter'sRemovewhile holding the metadata store write lock, with no deadline (it even strips the caller's cancellation). If the snapshotter never answers, the lock is held forever. Every snapshot operation on the node queues behind it, including CRIRunPodSandbox, so no new container can start. Nothing on the readiness path takes this lock, so the node keeps reporting Ready the whole time.flowchart TD K[kubelet] -->|Ready probe| S["CRI Status()"] K -->|RunPodSandbox| P[snapshot Prepare] S --> OK["returns OK - never takes the lock"] P --> L{{metadata store write lock}} GC[snapshot GC] -->|holds| L GC -->|"Remove() - no deadline"| SOCI[soci snapshotter<br/>out of fds, never answers] L -.->|blocked behind GC| PWe hit this in production: our soci snapshotter ran out of file descriptors and stopped answering, the GC's
Removeparked inwaitOnHeader, and the node could not start a single pod for 4.5 hours while showing Ready. Goroutine dumps are in the issue. The fd leak was a soci bug (fixed upstream in awslabs/soci-snapshotter#2043), but any proxy snapshotter that stalls reproduces this: one stuck RPC should not brick the node.Fix
Bound each GC-path
Removewith apkg/timeoutkey (io.containerd.timeout.snapshot.remove, default 30m), the same pattern as shim cleanup and bolt open timeouts.On the first timed-out
Removethe rest of the pass is abandoned, so a wedged snapshotter costs one timeout per GC cycle instead of one per orphan. Skipped snapshots stay orphaned and are retried next pass. The deferredCleanupcall is skipped in that case too, since it is an unbounded RPC to the same snapshotter that just failed to answer.Not in this PR
Walkruns under the same lock and is also unbounded. Left out to keep this change small; can follow up.