Skip to content

metadata: bound each content GC pass with a single timeout - #14025

Open
chansuke wants to merge 1 commit into
containerd:mainfrom
chansuke:bound-content-gc
Open

chansuke wants to merge 1 commit into
containerd:mainfrom
chansuke:bound-content-gc

Conversation

@chansuke

@chansuke chansuke commented Aug 24, 2026 •

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR prevents daemon-wide stalls caused by unresponsive content-store backends during metadata content garbage collection. It does so by bounding backend Delete and Abort calls (which currently run while holding the content store write lock and with cancellation stripped upstream) using configurable pkg/timeout keys, so a wedged proxy plugin can no longer block all content operations indefinitely.

Changes:

  • Add per-call GC timeouts for content backend Delete and Abort (io.containerd.timeout.gc.content.delete / .abort, default 30m) via pkg/timeout.
  • Apply those timeouts inside contentStore.garbageCollect when deleting orphaned blobs and aborting orphaned ingests.
  • Add synctest-backed unit tests to validate that GC abandons the pass after the first hung backend call and leaves remaining orphans for the next pass; document the new timeout keys in the config manpage.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
docs/man/containerd-config.toml.5.md Documents new timeouts keys for content GC abort/delete.
core/metadata/content.go Wraps GC Delete/Abort calls with timeout.WithContext and registers default durations.
core/metadata/content_test.go Adds tests ensuring hung backend calls time out and GC abandons the pass after the first timeout.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI review requested due to automatic review settings August 25, 2026 10:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Suppressed comments (1)

core/metadata/content.go:962

  • Even with per-Abort timeouts, the surrounding WalkStatusRefs/ListStatuses phase is still invoked under cs.l.Lock() with the original ctx and no deadline. If a proxy backend hangs in WalkStatusRefs or ListStatuses, GC can still hold the write lock indefinitely before it ever reaches the bounded Abort calls. Consider applying timeouts to those calls too (separate keys or a shared GC-content-status key).
		err = w.WalkStatusRefs(ctx, func(ref string) error {
			if _, ok := ingestSeen[ref]; !ok {
				abortCtx, cancel := timeout.WithContext(ctx, gcContentAbortTimeoutKey)
				err := cs.Store.Abort(abortCtx, ref)
				cancel()

Comment thread core/metadata/content.go Outdated
Comment on lines +935 to +939
err = cs.Store.Walk(ctx, func(info content.Info) error {
if _, ok := contentSeen[info.Digest.String()]; !ok {
if err := cs.Store.Delete(ctx, info.Digest); err != nil {
deleteCtx, cancel := timeout.WithContext(ctx, gcContentDeleteTimeoutKey)
err := cs.Store.Delete(deleteCtx, info.Digest)
cancel()
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]>
Copilot AI review requested due to automatic review settings September 8, 2026 14:28
@chansuke chansuke changed the title metadata: bound content store Delete and Abort during garbage collection metadata: bound each content GC pass with a single timeout Sep 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The current timeout wiring can cancel GC immediately when configured to 0 and should avoid doing additional work under the lock once the timeout is already exceeded.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment thread core/metadata/content.go
Comment on lines +864 to 868
gcCtx, cancel := timeout.WithContext(ctx, gcContentTimeoutKey)
defer cancel()

cs.l.Lock()
t1 := time.Now()
Comment thread core/metadata/content.go
Comment on lines +43 to +47
// gcContentTimeoutKey bounds one full content garbage collection pass: the
// backend Walk/Delete sweep and the ingest Abort sweep, all under the content
// store write lock. The deadline starts before lock acquisition; the wait
// itself is not interruptible, but its duration counts against the budget of
// the pass. An unresponsive content store (e.g. a hung proxy plugin RPC)
@NahumLitvin

Copy link
Copy Markdown
Contributor

Closing, superseded. Per @fuweid in #14026 the bound moves to the proxy client as an optional default_timeout, covering all 10 methods instead of one component at a time.

@NahumLitvin

Copy link
Copy Markdown
Contributor

Heads up: #14187 puts the timeout in the proxy client as an optional default_timeout, following @fuweid's suggestion in #14026. It covers the snapshot proxy only, so the content side still needs its own key because Writer outlives the call that created it. Leaving it to the maintainers whether that replaces the per-component approach here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

3 participants