Skip to content

Commit

Permalink
Issue ReactiveX#646: Illegal state transition from HALF_OPEN to OPEN/…
Browse files Browse the repository at this point in the history
…CLOSED. (ReactiveX#647)
  • Loading branch information
wantedlzx authored and RobWin committed Sep 25, 2019
1 parent b88ffa7 commit 1876763
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -653,11 +653,13 @@ private class HalfOpenState implements CircuitBreakerState {

private CircuitBreakerMetrics circuitBreakerMetrics;
private final AtomicInteger permittedNumberOfCalls;
private final AtomicBoolean isHalfOpen;

HalfOpenState() {
int permittedNumberOfCallsInHalfOpenState = circuitBreakerConfig.getPermittedNumberOfCallsInHalfOpenState();
this.circuitBreakerMetrics = CircuitBreakerMetrics.forHalfOpen(permittedNumberOfCallsInHalfOpenState, getCircuitBreakerConfig());
this.permittedNumberOfCalls = new AtomicInteger(permittedNumberOfCallsInHalfOpenState);
this.isHalfOpen = new AtomicBoolean(true);
}

/**
Expand Down Expand Up @@ -709,10 +711,14 @@ public void onSuccess(long duration, TimeUnit durationUnit) {
*/
private void checkIfThresholdsExceeded(Result result) {
if(result == ABOVE_THRESHOLDS){
transitionToOpenState();
if(isHalfOpen.compareAndSet(true, false)){
transitionToOpenState();
}
}
if(result == BELOW_THRESHOLDS){
transitionToClosedState();
if(isHalfOpen.compareAndSet(true, false)){
transitionToClosedState();
}
}
}

Expand Down

0 comments on commit 1876763

Please sign in to comment.