fix(shared-state): drop breaker deltas older than the fail window

During a Redis outage the queued failure deltas kept a replaced
gateway's loop alive for ever. A queued failure older than the fail
window cannot change the fleet count, so the breaker now drops it.
This commit is contained in:
2026-11-26 04:10:29 +00:00
parent 5cb01e2c4b
commit a9468f5d51
2 changed files with 52 additions and 2 deletions
+30
View File
@@ -294,3 +294,33 @@ func TestSharedInflightEndRestartsIdleStoppedLoop(t *testing.T) {
}
l.close()
}
func TestSharedBreakerDropsDeltasPastFailWindow(t *testing.T) {
store, clk := sharedTestEnv()
l := sharedTestLoop(store, clk)
b := testBreaker(l)
store.setFailIncr(errors.New("redis down"))
b.recordFailure("p")
l.refresh()
if !b.pending() {
t.Fatal("delta dropped inside the fail window")
}
clk.advance(testBrkWindow + time.Second)
if b.pending() {
t.Error("failure delta older than the fail window still pending")
}
}
func TestSharedStateIdleStopsDuringOutageAfterFailWindow(t *testing.T) {
store, clk := sharedTestEnv()
l := newSharedStateLoop(store, nil, nil)
l.nowFn = clk.now
l.every = 5 * time.Millisecond
b := testBreaker(l)
store.setFailIncr(errors.New("redis down"))
b.recordFailure("p")
waitLoop(t, l, true)
clk.advance(sharedStateIdleStop + time.Second)
waitLoop(t, l, false)
l.close()
}