fix(cli): avoid send on closed channel panic in status watch. Fixes #4372 #5056
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 408 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.360
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #5056"
general
weight: 0.35
kostis-codefresh
kubectl argo rollouts status(watch is the default) intermittently panics withsend on closed channelatstatus.go:76, the send inside the registered callback.The callback pushes every changed
RolloutInfointo an unbuffered channel thatWatchStatusreads. As soon asWatchStatussees Healthy or Degraded it returns and nobody receives any more, but the view controller keeps processing until the command returns andcancel()runs. If the rollout (or one of its ReplicaSets, pods, AnalysisRuns) changes in that window, the callback blocks in the send. WhenRunEreturns, deferred calls run in reverse order, sodefer close(rolloutUpdates)runs before the deferredcancel(), and the blocked send panics. Watching rollouts while a deploy is still changing pods, as in the issue, is what hits that window.#1796 (for #1747) changed
close(rolloutUpdates)intodefer close(rolloutUpdates), which narrowed the window but didn't close it. The close isn't needed:WatchStatushas already returned and nothing ranges over the channel or waits for it to close. So this removes it. A callback that is still blocked stays blocked until the process exits, which is harmless for a CLI command.The new test updates the rollout from inside the first status write, i.e. right before
WatchStatusreturns, so the late update is always in flight when the command exits. Without the fix it panics every time.Fixes #4372
Testing
go test ./pkg/kubectl-argo-rollouts/...go test -race ./pkg/kubectl-argo-rollouts/cmd/status/ -count=3go vet ./pkg/kubectl-argo-rollouts/...,golangci-lint run ./pkg/kubectl-argo-rollouts/cmd/status/...TestWatchStatusUpdateAfterDone: 5/5 runs panic withsend on closed channelon master, pass with this changeNot changed here:
get experiment --watchcloses its channel afterRunreturns in the same way, which can only race on Ctrl-C.Checklist:
[x] Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this is a chore.
[x] The title of the PR is (a) conventional with a list of types and scopes found here, (b) states what changed, and (c) suffixes the related issues number. E.g.
"fix(controller): Updates such and such. Fixes #1234".[x] I've signed my commits with DCO
[x] My builds are green. Try syncing with master if they are not.
[x] I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
[ ] I have run all tests locally (including the flaky ones) and they pass on my workstation
[x] I have used LLM/AI/Agent tools for this PR but I am responsible for all code of this PR
[x] I understand what the code does and WHY/HOW it works in several scenarios
[x] I know if my code is just adding new functionality or changing old functionality for existing users
[ ] My organization is added to USERS.md.