AniLink - v3.0.0
    Preparing search index...

    Function recordCircuitFailure

    • Counts a failed attempt and opens the circuit once the consecutive-failure budget is exhausted. Only availability failures (see isAvailabilityFailure) count: network errors, timeouts, 429s, and 5xx responses. Caller-side errors (4xx) and caller-initiated aborts say nothing about upstream health, so they never advance the streak. And because such a failure proves the upstream answered, it resets the streak like a success would: a stale 500-streak cannot trip the breaker after interleaved caller-side errors. Status-less GraphQL envelope errors are the exception (see isStreakNeutralFailure): they reset nothing, so a sustained outage that manifests as status-less envelope errors can no longer erase the streak other error classes accumulated. When such a failure, including a streak-neutral one, is the reserved post-cooldown probe, the breaker closes (the upstream answered, so it is reachable) instead of wedging the half-open state. When an availability failure is the reserved post-cooldown probe, it clears the half-open state and re-opens the breaker immediately so the next request fast-fails until the cooldown elapses again. The failed probe advances the probe-failure counter, which scales the next cooldown (see scaledCooldownMs) so repeated probe failures back off instead of starving the half-open state at one request per cooldown. Emits onCircuitOpen on the first trip into open (not on re-opens from a failed probe, which are a continuation of the same open period).

      Parameters

      • circuit: CircuitState | undefined

        The caller's breaker state, when the breaker is enabled.

      • breaker: { cooldownMs: number; threshold: number } | undefined

        The breaker configuration, when enabled.

      • normalized: AniLinkError

        The normalized failure from the request pipeline.

      • resolved: ResolvedRequestOptions

        The resolved request options, for the onCircuitOpen hook.

      • hookContext: RequestContext

        The request context, for the onCircuitOpen hook.

      • host: string

        The upstream host scope, for the onCircuitOpen hook.

      Returns void

      Nothing; mutates the breaker state.