Repository navigation
plugins/services/tasks: add timeout to per-task Stats() call in getTasksMetrics - #13877
Ayush-Rathor wants to merge 2 commits into
Conversation
Signed-off-by: Ayush-Rathor <[email protected]>
There was a problem hiding this comment.
🟡 Not ready to approve
The new lines introduce inconsistent indentation (not gofmt-aligned), which is likely to fail style/CI checks and should be corrected before merging.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Pull request overview
This PR prevents containerd’s Tasks service Metrics RPC from hanging indefinitely on a single unresponsive shim by applying an existing, configurable timeout to each per-task Stats() call during metrics collection.
Changes:
- Wrap each
tk.Stats()call ingetTasksMetricswithtimeout.WithContext(..., cmetrics.ShimStatsRequestTimeout). - Reuse the existing shim stats timeout key (
io.containerd.timeout.metrics.shimstats, default 2s) rather than introducing a new timeout setting.
File summaries
| File | Description |
|---|---|
| plugins/services/tasks/local.go | Adds a per-task timeout around Stats() to avoid wedging metrics collection/shutdown on an unresponsive shim. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
Co-authored-by: Copilot Autofix powered by AI <[email protected]> Signed-off-by: Ayush Rathor <[email protected]>
There was a problem hiding this comment.
🟢 Ready to approve
The change is small, consistent with existing timeout mechanisms, and directly addresses an identified indefinite-blocking failure mode without introducing API or behavior ambiguity beyond the intended timeout.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0 new
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
|
@austinvazquez Anything on this? |
What this PR fixes
Fixes/complements #13848 (companion to #13852). PR #13852 bounds the unbounded
shim.delete()call that can hangcontainerd's startup path (loadShims) forever if a leftover shim never replies. This PR bounds a second, structurally identical unbounded call that we found while investigating why containerd was also observed hanging on the graceful shutdown path in the same incident described in #13848.Root cause
getTasksMetrics(plugins/services/tasks/local.go) is the implementation behind the Tasks service'sMetricsRPC. It iterates every task on the node and callstk.Stats(ctx)for each one, sequentially, using whatever context the caller passed in — with no timeout applied at this layer:On the CRI side,
internal/cri/server/stats_collector.go'sStatsCollectorcalls this RPC once a second from a background goroutine (collectLoop), using a barecontext.Background()-derived context.Put together: if even one task's shim hangs on
Stats()(the same shim-unresponsive condition described in #13848 — sandbox already exited, shim doesn't answer a specific request), the entire per-second metrics-collection loop wedges on that one task indefinitely. Every other task silently stops getting metrics collected too, since the loop is sequential and never reaches them. And becauseStatsCollector.Stop()waits for that same wedged goroutine to exit, containerd's graceful shutdown (criService.Close()→c.statsCollector.Stop()) hangs for as long as the shim stays unresponsive — in practice, untilsystemd's stop timeout gives up and sendsSIGKILL. This matches the "Stop-side hang" behavior observed in #13848 before the node hit the (separately-fixed) startup hang on its next boot.We also note
getTasksMetrics's"collecting metrics for %s"error log line matches log lines we independently captured from an affected production node, which is what led us to this function.The fix
Wrap the per-task
Stats()call with a bounded timeout, using the timeout key containerd's own cgroups-based metrics collector (core/metrics/cgroups/v1andv2) already uses for exactly this same kind of call (ShimStatsRequestTimeout,io.containerd.timeout.metrics.shimstats, 2s default) — so this reuses an existing, already-tunable timeout rather than introducing a new config key, consistent with the approach in #13852.With this change, one wedged shim can no longer block metrics collection for every other task, and can no longer block
StatsCollector.Stop()indefinitely.