API Reference

Opossum

Circuit breaker for Node.js that stops calling a failing dependency and recovers it automatically.

Official Documentation ↗
CompatibilityThis documentation covers version v10.0.0. Check the official docs for the latest API surface.

Installation

npmnpm install opossum
pnpmpnpm add opossum
yarnyarn add opossum

Methods

Overview

Opossum implements the circuit breaker pattern. It watches failures of a wrapped function and, once failures cross a threshold, fails fast instead of hammering a sick dependency, then probes for recovery.

Core Methods

Construct a breaker around an async function with timeout and threshold options, call fire to invoke it, and register fallback plus event handlers for open, halfOpen, close and failure transitions.

Usage Notes

Wrap every remote call that can degrade, define a fallback such as a cached value, and emit metrics from the state-change events so you can see circuits opening before users do.

Common Pitfalls

Opening a circuit without a fallback turns dependency failure into user-visible errors. Thresholds that are too tight open on normal blips, while too loose settings delay protection. A single breaker for many endpoints couples their health.

Errors

The following points are quoted verbatim from the official documentation. 来源:https://cdn.jsdelivr.net/gh/nodeshift/opossum@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:51:21.098Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

FAQ

When does the circuit open and close?
It opens when the failure rate exceeds errorThresholdPercentage over the rolling window, then stays open for resetTimeout before allowing a trial request in half-open state.
How is a timeout handled?
If the wrapped function exceeds the timeout option, the call counts as a failure and rejects with a timeout error, which protects callers from hung dependencies.
Should I use one breaker per dependency?
Yes. Each dependency and endpoint should have its own breaker so one slow service does not open the circuit for unrelated calls. Share breakers per logical downstream operation.