mirror of
https://github.com/lukaszraczylo/traefikoidc.git
synced 2026-11-09 08:55:36 +00:00
fix(resilience): recover from unhealthy and close half-open on successes
The health check promoted to healthy only when the fail counter was above zero. The first success zeroed that counter, so a threshold of 2 or more never recovered. It now promotes on the status and the success streak. The breaker closed when admitted probes reached HalfOpenMaxRequests, not when that many succeeded. A new counter tracks successes.
This commit is contained in:
+4
-3
@@ -168,11 +168,12 @@ func (h *HealthCheckBackend) IsHealthy() bool {
|
||||
func (h *HealthCheckBackend) recordResult(success bool) {
|
||||
// #nosec G115 -- threshold config values are small integers that fit in int32
|
||||
if success {
|
||||
fails := h.consecutiveFails.Swap(0)
|
||||
h.consecutiveFails.Store(0)
|
||||
oks := h.consecutiveOK.Add(1)
|
||||
|
||||
// Check if we should transition to healthy
|
||||
if fails > 0 && oks >= int32(h.config.HealthyThreshold) {
|
||||
// Promote on a success streak. Keyed on the status, not on the fail
|
||||
// counter, which the first success of the streak already zeroed.
|
||||
if HealthStatus(h.status.Load()) != HealthHealthy && oks >= int32(h.config.HealthyThreshold) {
|
||||
oldStatus := HealthStatus(h.status.Swap(int32(HealthHealthy)))
|
||||
if oldStatus != HealthHealthy && h.config.OnStatusChange != nil {
|
||||
h.config.OnStatusChange(oldStatus, HealthHealthy)
|
||||
|
||||
Reference in New Issue
Block a user