Skip to content

Breaker

The Breaker is a sealed class that implements the circuit breaker pattern. It is a live object; create it and share it across the calls you intend to protect.

MemberDescription
Breaker(BreakerSettings? settings = null)Creates a new breaker. This constructor validates the settings and throws a ResilienceConfigurationException if they are invalid.
NameAn init-only property used for diagnostics and health endpoints.
SettingsThe BreakerSettings used to configure the breaker.
StateThe current state of the breaker. If a breaker is open but the break duration has elapsed, it reports HalfOpen because the next call will be treated as a probe. Reading this property does not consume a probe slot.
OpenedAtThe timestamp of when the breaker last opened, or null if it is currently closed.
Isolate()Forces the breaker into the Isolated state. An isolated breaker does not self-heal.
Reset()Closes the breaker and clears its failure history.

Isolate and Reset do not raise events because they are administrative actions and not triggered by a specific call.

BreakerState

The BreakerState enum defines the possible states of the circuit breaker:

ValueDescription
ClosedThe breaker is operating normally. Calls pass through, and outcomes are sampled.
OpenThe breaker has tripped. Calls are refused until the break duration expires.
HalfOpenThe break duration has expired. A limited number of trial calls (probes) are allowed through.
IsolatedThe breaker has been forced open via the Isolate method.

BreakerSettings

BreakerSettings is a sealed record used to configure the breaker's trip and reset logic. All properties are init-only.

PropertyDefaultDescription
ConsecutiveFailures5The number of consecutive failures required to trip the breaker.
FailureRationullAn optional rate-based trip threshold in the range (0, 1]. This is evaluated alongside the consecutive failure counter.
MinimumCalls20The minimum number of sampled calls in the window before a rate-based trip is evaluated.
Window30 sThe sliding window duration over which rates are measured.
SlowCallThresholdnullThe duration above which an attempt is considered "slow," even if it succeeded.
SlowCallRatio0.5The proportion of slow calls in the window that will trip the breaker.
BreakDuration15 sThe duration of the first break.
MaxBreakDuration2 minThe maximum break duration. The break duration doubles with each consecutive trip up to this limit. Set this equal to BreakDuration to disable growth.
HalfOpenProbes1The number of concurrent trial calls allowed while in the HalfOpen state.
ProbeSuccesses2The number of successful probes required to return the breaker to the Closed state.
TimeTimeProvider.SystemThe clock used for timing. The breaker maintains its own clock so its state can be read by health endpoints that do not have access to a policy.
Validate()N/AValidates the settings and throws a ResilienceConfigurationException listing all found problems.

Implementation details

  • Evaluation: Rate-based trips (including the SlowCallThreshold) are not evaluated until MinimumCalls have occurred within the window.
  • Resource Efficiency: Window arrays are only allocated if a rate-based trip is configured. A breaker relying solely on consecutive failures requires no arrays.
  • Sampling: The breaker samples individual attempts. Only Transient outcomes are counted as evidence of failure.

For a detailed explanation of the logic, see Breaker internals.

Released under the MIT License.