Extract backendCheck type for per-backend goroutine lifecycle#4532
Extract backendCheck type for per-backend goroutine lifecycle#4532ChrisJBurns merged 3 commits intomainfrom
Conversation
Introduce a backendCheck struct that owns the backend snapshot and cancel function for a single health check goroutine. This replaces the raw context.CancelFunc values in the activeChecks map and consolidates the scattered goroutine start/stop mechanics into start() and stop() methods. The change decouples per-backend lifecycle management from the Monitor's coordination logic in Start() and UpdateBackends(), making the restart-on-property-change logic clearer. It also eliminates the need for a separate oldBackends map in UpdateBackends since activeChecks now carries the backend data directly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@claude Please review this with the agents. only raise critical/high issues and medium issues that are non controversial. ignore low/informational style / nits. recommend approval or rejection. |
|
Claude finished @ChrisJBurns's task in 2m 50s —— View job PR Review — Extract
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4532 +/- ##
==========================================
- Coverage 68.85% 68.82% -0.03%
==========================================
Files 505 505
Lines 52318 52316 -2
==========================================
- Hits 36022 36009 -13
- Misses 13506 13515 +9
- Partials 2790 2792 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add thread-safety comments to backendCheck struct, start(), and stop() documenting that callers must hold the Monitor's locks. start() requires both m.mu and m.backendsMu to prevent wg.Add() racing with wg.Wait() in Stop(). stop() requires m.backendsMu. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@claude Please re-review this with the agents. only raise critical/high issues and medium issues that are non controversial. ignore low/informational style / nits. recommend approval or rejection. |
|
Claude finished @ChrisJBurns's task in 2m 19s —— View job PR Review — Extract
|
The directive referenced G118 which does not exist in the gosec ruleset. The cancel func is stored in bc.cancel on the next line so no linter complains without the suppression. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
| func (bc *backendCheck) start(parentCtx context.Context, m *Monitor, isInitial bool) { | ||
| ctx, cancel := context.WithCancel(parentCtx) | ||
| bc.cancel = cancel | ||
| m.wg.Add(1) |
There was a problem hiding this comment.
It's a bit weird to reach back into the parent's state here. Fine for now, since we can gradually separate these two.
…ok#4532) * Extract backendCheck type for per-backend goroutine lifecycle Introduce a backendCheck struct that owns the backend snapshot and cancel function for a single health check goroutine. This replaces the raw context.CancelFunc values in the activeChecks map and consolidates the scattered goroutine start/stop mechanics into start() and stop() methods. The change decouples per-backend lifecycle management from the Monitor's coordination logic in Start() and UpdateBackends(), making the restart-on-property-change logic clearer. It also eliminates the need for a separate oldBackends map in UpdateBackends since activeChecks now carries the backend data directly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Document locking requirements on backendCheck methods Add thread-safety comments to backendCheck struct, start(), and stop() documenting that callers must hold the Monitor's locks. start() requires both m.mu and m.backendsMu to prevent wg.Add() racing with wg.Wait() in Stop(). stop() requires m.backendsMu. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Remove bogus nolint:gosec directive on context.WithCancel The directive referenced G118 which does not exist in the gosec ruleset. The cancel func is stored in bc.cancel on the next line so no linter complains without the suppression. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
Addresses review feedback from #4524: the
activeChecksmap held rawcontext.CancelFuncvalues, and goroutine lifecycle (cancel, create context, add to waitgroup, launch goroutine) was duplicated acrossStart()andUpdateBackends().This introduces a
backendCheckstruct that owns both the backend snapshot and the cancel function for a single health check goroutine, withstart()andstop()methods.activeChecksnow holds*backendCheckinstead of bare cancel funcs, which:oldBackendsmap inUpdateBackendssinceactiveChecksnow carries backend data directlyType of change
Changes
pkg/vmcp/health/monitor.gobackendCheckstruct withstart()/stop()methods; updateMonitor.activeCheckstype frommap[string]context.CancelFunctomap[string]*backendCheck; simplifyStart()andUpdateBackends()Test plan
Generated with Claude Code