Skip to content

feat(client): retry + circuit-breaker (#39)#244

Merged
mvillmow merged 2 commits into
mainfrom
39-retry-circuit-breaker
May 16, 2026
Merged

feat(client): retry + circuit-breaker (#39)#244
mvillmow merged 2 commits into
mainfrom
39-retry-circuit-breaker

Conversation

@mvillmow
Copy link
Copy Markdown
Contributor

Summary

  • Adds opt-in retry-with-exponential-backoff and a three-state circuit breaker (CLOSED/OPEN/HALF_OPEN) to HttpTestClient.
  • Only transport failures (status == 0) are retried; deliberate 4xx/5xx responses pass through unchanged.
  • Backoff is min(base * mult^attempt, cap) * uniform(0.5, 1.5); no sleep after the final attempt.
  • New RetryPolicy and CircuitBreakerConfig structs default to no-op behaviour (max_retries = 0, failure_threshold = 0), so existing single-arg HttpTestClient("...") constructions compile and behave identically — the change is ABI-conservative on purpose (cf. PR refactor: expose timeout constants as constructor params (#81) #231 cascade).

ABI / migration

  • Constructor gains two defaulted parameters — fully source-compatible with all existing call sites.
  • Header adds <chrono> and forward-declares a private CircuitBreaker (pimpl-style), so <atomic>, <mutex>, <random> stay in the .cpp.

Test plan

  • New test/src/test_http_client_retry_unit.cpp covers default-policy constants, retry exhaustion against refused ports, HTTP-error non-retry, breaker trip/half-open/disabled paths via the in-process MockServer pattern.
  • CI: projectcharybdis_tests builds and discovers all new tests.
  • Existing HttpTestClientUnit / HttpTestClientOnline tests still pass (default policy means zero behaviour drift).

Closes #39

Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

@mvillmow mvillmow enabled auto-merge (squash) May 14, 2026 03:04
mvillmow and others added 2 commits May 15, 2026 18:55
Adds opt-in retry-with-exponential-backoff and a three-state circuit
breaker (CLOSED/OPEN/HALF_OPEN) to HttpTestClient so chaos tests do not
fail on the transient connection errors they are designed to create.

ABI-conservative: new RetryPolicy / CircuitBreakerConfig structs default
to no-op behaviour (max_retries=0, failure_threshold=0), so existing
single-argument constructions compile and behave identically. Only
status==0 (transport failure) is retried; deliberate 4xx/5xx replies are
returned unchanged.

Covered by test/src/test_http_client_retry_unit.cpp using the in-process
MockServer pattern from test_http_client_unit.cpp.

Closes #39

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Move `run_with_retry` from anonymous-namespace free function to a private
  static template member of `HttpTestClient` so it can refer to the
  private `CircuitBreaker` nested type without exposing it publicly.
- Change template signature from `Fn&& fn` (forwarding reference never
  std::forward'd, and invoked in a loop) to `Fn func` by value — safe for
  the lambda callsites and removes the clang-tidy warning.
- Rename constructor and ctor params `cb` → `breaker_cfg` to satisfy
  identifier-length checks on public API.
- Add `std::uint8_t` underlying-type to `BreakerState` enum.
- Drop redundant `{}` initializer on `opened_at_` (value-initialised by
  default).
- Rename test-local identifiers (`p`/`c`/`cb`) to descriptive names and
  add `const` to value-only locals to satisfy
  `misc-const-correctness` / `readability-identifier-length`.
- Use `auto` for the static_cast<double>() result of base_delay_ms.
- clang-format -i over all three changed files for the format check.
@mvillmow mvillmow force-pushed the 39-retry-circuit-breaker branch from a1609bc to bb0ffd9 Compare May 16, 2026 08:41
@mvillmow mvillmow merged commit ae2583a into main May 16, 2026
34 of 35 checks passed
@mvillmow mvillmow deleted the 39-retry-circuit-breaker branch May 16, 2026 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MINOR] §9: No retry/circuit-breaker logic in HttpTestClient

1 participant