go.missing_circuit_breaker
Stability
High
Detects HTTP client calls to external services without circuit breaker protection, which can cause cascading failures.
Why It Matters
Section titled “Why It Matters”Without circuit breakers:
- Cascading failures — One slow service brings down everything
- Resource exhaustion — Goroutines pile up waiting for responses
- Extended outages — Failing service never gets time to recover
- Poor user experience — All requests slow down, not just affected ones
Example
Section titled “Example”// ❌ Before (no circuit breaker)func fetchData(url string) ([]byte, error) { resp, err := http.Get(url) if err != nil { return nil, err } return io.ReadAll(resp.Body)}// ✅ After (with circuit breaker)import "github.com/sony/gobreaker"
var cb = gobreaker.NewCircuitBreaker(gobreaker.Settings{ Name: "api", MaxRequests: 5, Interval: 10 * time.Second, Timeout: 30 * time.Second, ReadyToTrip: func(counts gobreaker.Counts) bool { return counts.ConsecutiveFailures > 5 },})
func fetchData(url string) ([]byte, error) { result, err := cb.Execute(func() (interface{}, error) { resp, err := http.Get(url) if err != nil { return nil, err } return io.ReadAll(resp.Body) }) if err != nil { return nil, err } return result.([]byte), nil}What Unfault Detects
Section titled “What Unfault Detects”- HTTP calls without circuit breaker wrapper
- gRPC client calls without breakers
- External service integrations without failure isolation
- Database connections without circuit protection
Auto-Fix
Section titled “Auto-Fix”Unfault generates patches using github.com/sony/gobreaker:
import "github.com/sony/gobreaker"
var circuitBreaker = gobreaker.NewCircuitBreaker(gobreaker.Settings{ Name: "external-api", MaxRequests: 3, Timeout: 60 * time.Second,})