Skip to content

Commit dcc2667

Browse files
authored
FFM-12005 Fix PollCacheHealth func (#363)
**What** - Moves `defer ticker.Stop` inside the goroutine **Why** - Having it before the goroutine means we end up stopping the ticker as soon as this function ends, meaning we never end up updating the cache health after startup **Testing** - Manual testing
1 parent cc5e999 commit dcc2667

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

health/health.go

+4-10
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ func (p ProxyHealth) Health(ctx context.Context) domain.HealthResponse {
123123

124124
func (p ProxyHealth) PollCacheHealth(ctx context.Context, interval time.Duration) {
125125
ticker := time.NewTicker(interval)
126-
defer ticker.Stop()
127126

128127
// Check cache health when we first start so we don't have to wait for the
129128
// ticker to expire before we know the state of the cache health at startup
@@ -134,23 +133,18 @@ func (p ProxyHealth) PollCacheHealth(ctx context.Context, interval time.Duration
134133
}
135134

136135
go func() {
136+
defer ticker.Stop()
137+
137138
for {
138139
select {
139140
case <-ctx.Done():
140141
return
141142
case <-ticker.C:
142143
if err := p.cacheHealth(ctx); err != nil {
143144
p.cacheHealthy.Set(false)
144-
continue
145+
} else {
146+
p.cacheHealthy.Set(true)
145147
}
146-
147-
// If the current status is already healthy then we don't
148-
// need to do anything
149-
if currentStatus := p.cacheHealthy.Get(); currentStatus {
150-
continue
151-
}
152-
153-
p.cacheHealthy.Set(true)
154148
}
155149
}
156150
}()

0 commit comments

Comments
 (0)