From e53d1729be63e5812080331e1094c5523b82b2f1 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Tue, 9 Aug 2016 17:33:58 +0200 Subject: [PATCH] Make request_allowed? thread safe --- lib/semian/circuit_breaker.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/semian/circuit_breaker.rb b/lib/semian/circuit_breaker.rb index f732ceb75..f5109ce9c 100644 --- a/lib/semian/circuit_breaker.rb +++ b/lib/semian/circuit_breaker.rb @@ -15,6 +15,8 @@ def initialize(name, exceptions:, success_threshold:, error_threshold:, error_ti end def acquire + half_open if open? && error_timeout_expired? + raise OpenCircuitError unless request_allowed? result = nil @@ -30,9 +32,7 @@ def acquire end def request_allowed? - return true if closed? - half_open if error_timeout_expired? - !open? + closed? || half_open? || (open? && error_timeout_expired?) end def mark_failed(_error)