Skip to content

Fix time-based circuit breaker statistics after idle window reset - #402

Open
coder6955 wants to merge 1 commit into
failsafe-lib:masterfrom
coder6955:codex/fix-circuit-stats-idle-reset
Open

coder6955 wants to merge 1 commit into
failsafe-lib:masterfrom
coder6955:codex/fix-circuit-stats-idle-reset

Conversation

@coder6955

Copy link
Copy Markdown

Fixes #390.

After a time-based circuit breaker has been idle for longer than its window, getCurrentBucket() resets the buckets but returns the previously current bucket. The first new execution is recorded into that stale bucket instead of bucket zero. A subsequent rotation can remove that execution before its new window expires; two failures that should meet the threshold can leave the circuit closed.

The same path also exposes a timestamp problem: reset() initializes the remaining buckets with future start times, but rotation adds an entire window to those times. Results can then remain counted beyond their window. Rotation now derives each bucket's start time from the preceding bucket, and the full-reset path returns the new current bucket.

Regression coverage uses the existing fake clock, with no sleeps:

  • Success and failure results after inactivity from all four previous bucket positions, checking counts/rates throughout the new window and expiry at its boundary.
  • A circuit configured for two failures in four seconds, verifying that it opens after two post-idle failures one second apart.

Validation on Temurin Java 8:

  • Both new regression methods fail against unchanged upstream production code.
  • mvn -pl core -Dtest=TimedCircuitStatsTest,ClosedStateTest -DforkCount=0 test: 19 tests passed.
  • mvn -DforkCount=0 test: all 333 tests passed (315 core, 9 OkHttp, 9 Retrofit), with no failures, errors, or skips.
  • git diff --check passed.

The local Windows Surefire launcher stalled when spawning a separate JVM, so these runs used -DforkCount=0. No build configuration was changed; the upstream Java 8/11/17 CI matrix remains applicable.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Question] TimedCircuitStats.getCurrentBucket() returns the previous bucket instead of current one after the reset()

1 participant