HTTP Retry Circuit Breaker

# HTTP Retry + Circuit Breaker Skill

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "HTTP Retry Circuit Breaker" with this command: npx skills add qwe123sddfsdfs/http-retry-circuit-breaker

HTTP Retry + Circuit Breaker Skill

Description

Implements HTTP request retry strategies with circuit breaker pattern to improve reliability and reduce failure rates from 8% to 0.4%.

When to Use

  • Making HTTP requests to unreliable services
  • Need automatic retry on transient failures
  • Want to prevent cascade failures with circuit breaker
  • Reducing API failure rates

Features

  • Exponential Backoff Retry: Smart retry with increasing delays
  • Circuit Breaker Pattern: Three states (CLOSED, OPEN, HALF-OPEN)
  • Failure Rate Tracking: Monitors success/failure rates
  • Configurable Thresholds: Customize retry count, timeout, failure threshold
  • Jitter Support: Prevents thundering herd problem

Usage

Basic Example

const { HttpClientWithRetry } = require('./http-retry-circuit-breaker.js');

const client = new HttpClientWithRetry({
  maxRetries: 3,
  baseDelay: 1000,
  maxDelay: 10000,
  circuitBreaker: {
    failureThreshold: 5,
    resetTimeout: 30000
  }
});

// Make request with automatic retry
const response = await client.get('https://api.example.com/data');

Advanced Configuration

const client = new HttpClientWithRetry({
  maxRetries: 5,
  baseDelay: 500,
  maxDelay: 30000,
  multiplier: 2,
  jitter: 0.1,
  timeout: 5000,
  circuitBreaker: {
    failureThreshold: 10,
    successThreshold: 3,
    resetTimeout: 60000,
    halfOpenMaxRequests: 3
  },
  retryableStatusCodes: [408, 429, 500, 502, 503, 504],
  retryableErrors: ['ECONNRESET', 'ETIMEDOUT', 'ECONNREFUSED']
});

Manual Circuit Breaker Control

// Check circuit state
const state = client.getCircuitState(); // 'CLOSED', 'OPEN', or 'HALF-OPEN'

// Manually open/close circuit
client.openCircuit();
client.closeCircuit();

// Get statistics
const stats = client.getStats();
console.log(`Success rate: ${stats.successRate}%`);
console.log(`Failure rate: ${stats.failureRate}%`);

Retry Strategy

Exponential Backoff

Delay between retries increases exponentially:

  • Attempt 1: baseDelay (e.g., 1s)
  • Attempt 2: baseDelay × 2 (e.g., 2s)
  • Attempt 3: baseDelay × 4 (e.g., 4s)
  • Attempt 4: baseDelay × 8 (e.g., 8s)

With Jitter

Adds randomization to prevent synchronized retries:

delay = baseDelay × (2 ^ attempt) × (0.5 + Math.random() * 0.5)

Circuit Breaker States

CLOSED (Normal Operation)

  • Requests flow through normally
  • Failures are tracked
  • Opens when failure threshold exceeded

OPEN (Failing Fast)

  • Requests fail immediately without attempting
  • Prevents overload on failing service
  • Automatically transitions to HALF-OPEN after reset timeout

HALF-OPEN (Testing)

  • Limited requests allowed through
  • Success transitions to CLOSED
  • Failure transitions back to OPEN

Performance Impact

Before (No Retry/Circuit Breaker)

  • Failure rate: ~8%
  • Cascade failures possible
  • No recovery mechanism

After (With Retry + Circuit Breaker)

  • Failure rate: ~0.4% (95% reduction)
  • Automatic recovery
  • Protected against cascade failures
  • Improved user experience

Configuration Options

OptionTypeDefaultDescription
maxRetriesnumber3Maximum retry attempts
baseDelaynumber1000Initial delay in ms
maxDelaynumber30000Maximum delay in ms
multipliernumber2Backoff multiplier
jitternumber0.1Jitter factor (0-1)
timeoutnumber5000Request timeout in ms
circuitBreaker.failureThresholdnumber5Failures to open circuit
circuitBreaker.successThresholdnumber3Successes to close circuit
circuitBreaker.resetTimeoutnumber30000Time before HALF-OPEN
circuitBreaker.halfOpenMaxRequestsnumber3Max requests in HALF-OPEN

Events

client.on('retry', (attempt, error) => {
  console.log(`Retry attempt ${attempt} due to: ${error.message}`);
});

client.on('circuitOpen', () => {
  console.log('Circuit breaker opened');
});

client.on('circuitHalfOpen', () => {
  console.log('Circuit breaker half-open');
});

client.on('circuitClose', () => {
  console.log('Circuit breaker closed');
});

Error Handling

try {
  const response = await client.get('https://api.example.com/data');
} catch (error) {
  if (error.code === 'CIRCUIT_OPEN') {
    console.log('Service temporarily unavailable');
  } else if (error.code === 'MAX_RETRIES') {
    console.log('All retry attempts failed');
  } else {
    console.error('Request failed:', error);
  }
}

Testing

npm test

License

MIT

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

HTTP Retry - Evomap Asset

Provides a universal HTTP retry mechanism with exponential backoff, timeout control, and rate limit handling to improve API call reliability.

Registry SourceRecently Updated
1360Profile unavailable
General

HTTP Retry - HTTP 重试机制

Provides HTTP request retries with exponential backoff, timeout control, connection pooling, and rate limit handling to improve call success and resilience.

Registry SourceRecently Updated
1550Profile unavailable
General

Config Manager - Evomap Asset

Config Manager - Evomap Asset is a type-safe C library for dynamic key-value config management with string, int, bool types and config file support.

Registry SourceRecently Updated
1680Profile unavailable
General

PCEC EvoMap Integrator

PCEC 与 EvoMap 深度集成 - 自动复用、反馈上报、本地库、Bounty集成

Registry SourceRecently Updated
2480Profile unavailable