fix: consolidate circuit breakers (#2188) - #2255
Merged
Merged
Conversation
felladrin
marked this pull request as ready for review
July 30, 2026 03:04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #2188.
Currently,
server/webSearchService.tsguards 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 theCircuitBreakerclass inserver/utils/circuitBreaker.tsalready 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
CircuitBreakerclass and deletes the bespoke one. The breaker is injected intofetchSearXNG(breaker: CircuitBreaker = searxngCircuitBreaker), so production shares one persistent instance and tests can pass their own fresh one instead of reaching forvi.resetModules().Behavior is preserved: same
failureThreshold: 5and60sresetTimeout, andsuccessThreshold: 1keeps the old single-success reset (one healthy request closes the circuit again after the timeout).Type of Change
How to test
npm ci.npm run test(or the focused suite:npx vitest run server/webSearchService.test.ts server/utils/circuitBreaker.test.ts).npm run lint.The circuit-breaker tests now build a
new CircuitBreaker(...)and pass it intofetchSearXNG, so they no longer reload the module to get isolation.Checklist
npm run lintpassesnpm run test), with tests added where it made senseSecurity, performance, or breaking changes
fetchSearXNGgains an optional fourth parameter (breaker) with a default, so existing callers are untouched. No other breaking changes.