Skip to content

fix: consolidate circuit breakers (#2188) - #2255

Merged
felladrin merged 1 commit into
mainfrom
fix/2188-consolidate-circuit-breakers
Jul 30, 2026
Merged

fix: consolidate circuit breakers (#2188)#2255
felladrin merged 1 commit into
mainfrom
fix/2188-consolidate-circuit-breakers

Conversation

@felladrin

Copy link
Copy Markdown
Owner

Description

Fixes #2188.

Currently, server/webSearchService.ts guards SearXNG with a bespoke module-level circuit breaker. Its state lives for the whole process lifetime with no reset hook, so it can't be built fresh in a test. Meanwhile the CircuitBreaker class in server/utils/circuitBreaker.ts already covers this (per-key, HALF_OPEN-aware) and has its own tests, but nothing in production imports it. So the tested code is dead and the live code is untested.

This PR routes SearXNG through the CircuitBreaker class and deletes the bespoke one. The breaker is injected into fetchSearXNG (breaker: CircuitBreaker = searxngCircuitBreaker), so production shares one persistent instance and tests can pass their own fresh one instead of reaching for vi.resetModules().

Behavior is preserved: same failureThreshold: 5 and 60s resetTimeout, and successThreshold: 1 keeps the old single-success reset (one healthy request closes the circuit again after the timeout).

Type of Change

  • Bug fix
  • New feature
  • Documentation
  • Other (refactor, build, chore)

How to test

  1. Run npm ci.
  2. Run npm run test (or the focused suite: npx vitest run server/webSearchService.test.ts server/utils/circuitBreaker.test.ts).
  3. Run npm run lint.

The circuit-breaker tests now build a new CircuitBreaker(...) and pass it into fetchSearXNG, so they no longer reload the module to get isolation.

Checklist

  • npm run lint passes
  • Tests pass (npm run test), with tests added where it made sense

Security, performance, or breaking changes

fetchSearXNG gains an optional fourth parameter (breaker) with a default, so existing callers are untouched. No other breaking changes.

@felladrin
felladrin marked this pull request as ready for review July 30, 2026 03:04
@felladrin
felladrin merged commit 76553e4 into main Jul 30, 2026
7 checks passed
@felladrin
felladrin deleted the fix/2188-consolidate-circuit-breakers branch July 30, 2026 03:04
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.

Consolidate circuit breakers: route SearXNG through the tested class, delete the bespoke one

1 participant