From 0637360b31aa30976052d2546d4d9c293c3aa7ca Mon Sep 17 00:00:00 2001 From: Owen Date: Mon, 15 Dec 2025 12:10:47 -0500 Subject: [PATCH] Fix healthcheck interval not resetting Ref PAN-158 --- healthcheck/healthcheck.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/healthcheck/healthcheck.go b/healthcheck/healthcheck.go index 23ca4bd..8de3008 100644 --- a/healthcheck/healthcheck.go +++ b/healthcheck/healthcheck.go @@ -58,7 +58,7 @@ type Target struct { LastCheck time.Time `json:"lastCheck"` LastError string `json:"lastError,omitempty"` CheckCount int `json:"checkCount"` - ticker *time.Ticker + timer *time.Timer ctx context.Context cancel context.CancelFunc } @@ -304,26 +304,26 @@ func (m *Monitor) monitorTarget(target *Target) { go m.callback(m.GetTargets()) } - // Set up ticker based on current status + // Set up timer based on current status interval := time.Duration(target.Config.Interval) * time.Second if target.Status == StatusUnhealthy { interval = time.Duration(target.Config.UnhealthyInterval) * time.Second } logger.Debug("Target %d: initial check interval set to %v", target.Config.ID, interval) - target.ticker = time.NewTicker(interval) - defer target.ticker.Stop() + target.timer = time.NewTimer(interval) + defer target.timer.Stop() for { select { case <-target.ctx.Done(): logger.Info("Stopping health check monitoring for target %d", target.Config.ID) return - case <-target.ticker.C: + case <-target.timer.C: oldStatus := target.Status m.performHealthCheck(target) - // Update ticker interval if status changed + // Update timer interval if status changed newInterval := time.Duration(target.Config.Interval) * time.Second if target.Status == StatusUnhealthy { newInterval = time.Duration(target.Config.UnhealthyInterval) * time.Second @@ -332,11 +332,12 @@ func (m *Monitor) monitorTarget(target *Target) { if newInterval != interval { logger.Debug("Target %d: updating check interval from %v to %v due to status change", target.Config.ID, interval, newInterval) - target.ticker.Stop() - target.ticker = time.NewTicker(newInterval) interval = newInterval } + // Reset timer for next check with current interval + target.timer.Reset(interval) + // Notify callback if status changed if oldStatus != target.Status && m.callback != nil { logger.Info("Target %d status changed: %s -> %s",