Skip to content

fix(notifier): stop on closed target set channel - #19182

Closed
aknuds1 wants to merge 1 commit into
prometheus:mainfrom
aknuds1:arve/notifier-closed-sync-channel
Closed

aknuds1 wants to merge 1 commit into
prometheus:mainfrom
aknuds1:arve/notifier-closed-sync-channel

Conversation

@aknuds1

@aknuds1 aknuds1 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

The discovery manager closes its target-set channel when it stops. The notifier's unlabeled break only exited the inner select, so the target update loop repeatedly received from the closed channel and busy-spun.

Return from the target update loop when the channel closes, but keep Run blocked until Stop is called. This preserves shutdown ordering so rule evaluation can finish before notification send loops are drained and cleaned up.

Follow-up to #19149. Fixes the same class of bug.

Which issue(s) does the PR fix:

Release notes for end users (ALL commits must be considered).

Reviewers should verify clarity and quality.

[BUGFIX] Notifier: Prevent high CPU usage when the Alertmanager service discovery channel closes

The discovery manager closes its target-set channel when it stops. The
notifier's unlabeled break only exited the inner select, so the target update
loop repeatedly received from the closed channel and busy-spun.

Return from the target update loop when the channel closes, but keep Run
blocked until Stop is called. This preserves shutdown ordering so rule
evaluation can finish before notification send loops are drained and cleaned
up.

Signed-off-by: Arve Knudsen <[email protected]>
@aknuds1
aknuds1 requested a review from a team as a code owner July 14, 2026 08:12
@aknuds1
aknuds1 requested a review from cstyan July 14, 2026 08:12
@aknuds1

aknuds1 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

Converting to draft, while waiting on feedback from overlapping PR #17859.

Comment thread notifier/manager.go
func (n *Manager) Run(tsets <-chan map[string][]*targetgroup.Group) {
n.targetUpdateLoop(tsets)
// Wait for Stop even if the target update channel closes so callers control when send loops are cleaned up.
<-n.stopRequested

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Did you mean to have a defer here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, this is the intended logic. The call to targetUpdateLoop blocks until either n.stopRequested is closed or tsets is closed. The idea is to retain the behaviour before the fix, of waiting until n.stopRequested is closed before moving on to cleaning send loops.

@aknuds1

aknuds1 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favour of #17859.

@aknuds1 aknuds1 closed this Jul 15, 2026
@aknuds1
aknuds1 deleted the arve/notifier-closed-sync-channel branch July 15, 2026 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants