Repository navigation
Fix send on closed channel panic from scheduled status checks - #45
Merged
stefanprodan merged 1 commit intoNov 26, 2026
Merged
stefanprodan merged 1 commit into
stefanprodan merged 1 commit into
Conversation
ObjectStatusReporter schedules a delayed status check for objects with unschedulable Pods. That check runs in its own goroutine, which nothing waited for before the informer's event channel was closed. If the watch was stopped while the check was between reading the object and sending the result, it panicked with "send on closed channel". Track the scheduled check goroutines in a per-informer WaitGroup and wait on it before closing the channel, in both the sync and async event handler paths. Assisted-by: claude-code/claude-sonnet-5-5 Signed-off-by: Adham Kiwan <adhamkiwan@outlook.com>
Adham-Kiwan
force-pushed
the
fix/status-check-send-on-closed-channel
branch
from
November 25, 2026 23:02
97bde2b to
14af06a
Compare
stefanprodan
approved these changes
Nov 26, 2026
stefanprodan
left a comment
Member
There was a problem hiding this comment.
LGTM
Thanks @Adham-Kiwan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a
send on closed channelpanic inObjectStatusReporter, reported by Helm users in helm/helm#32951.Cause
When a watched object has an unschedulable Pod, the event handler calls
taskManager.Schedule, which re-reads the object afterstatus.ScheduleWindowin a new goroutine and sends the result on the informer's event channel. Nothing waited for that goroutine:eventChas soon asinformer.Runreturned;If the watch is stopped while a check is between reading the object and sending the result, it sends on a closed channel and the process panics.
Fix
Each informer now has one
WaitGroupcovering every goroutine, other than the informer's own, that can send on its channel.taskManager.Scheduleregisters its goroutine in it, and both paths wait beforeclose(eventCh).informer.Runonly returns after its event handlers have returned, so no new check can be registered from a handler once the wait has started (in the async path, a check registered by an in-flight computation is added while the counter is still non-zero). Checks that have not fired exit as soon as the informer context is cancelled.One behaviour change: shutdown now waits for a check that is already running. The read receives the cancelled context, so a context-aware client returns promptly.
Testing
TestStopWaitsForScheduledStatusCheck, covering the sync (workers=1) and async (workers=8) paths. Without the fix both fail withevent channel closed while a status check was in flight. It takes about 15s because it waits forstatus.ScheduleWindow; the two cases run in parallel.go test -race -count=3 ./pkg/kstatus/watcher/ -run TestStopWaitsForScheduledStatusCheck,make test,make lintandgo vet ./pkg/...pass.I have not reproduced the original crash on a live cluster; the test reproduces the ordering that leads to it.
AI disclosure
This change was written with the help of an AI agent (Claude Code), as noted in the
Assisted-bycommit trailer.🤖 Generated with Claude Code