Uploaded image for project: 'Thorntail'
  1. Thorntail
  2. THORN-1932

MP fault tolerance: circuit breaker doesn't open if there was at least one success

    Details

      Description

      This is the code that figures out if the failure threshold has been reached in SynchronousCircuitBreaker:

          private boolean isFailureThresholdReached() {
              int requestCount = getRequestCount();
              int requestVolumeThreshold = config.get(CircuitBreakerConfig.REQUEST_VOLUME_THRESHOLD);
              if (requestCount < requestVolumeThreshold) {
                  return false;
              }
              double failureCheck = failureCount.get() / requestCount;
              double failureRatio = config.get(CircuitBreakerConfig.FAILURE_RATIO);
              return (failureCheck >= failureRatio) || (failureRatio <= 0 && failureCheck == 1);
          }
      

      Notably, the line double failureCheck = failureCount.get() / requestCount; divides two int-s, which is also always an int. That is, if the quotient is not an integer, the failureCheck will be wrong.

      For example, if there was 1 successful invocation and 20 failed invocations, the failureCheck should be 20/21 = cca 0.95, but will be 0.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                lthon Ladislav Thon
                Reporter:
                lthon Ladislav Thon
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: