feat(utils): implement circuit breaker pattern for resilient network clients#420
Merged
Conversation
Add circuit_breaker class with three-state machine (closed, open, half-open) to prevent cascade failures and provide fast-fail behavior when backend services are unavailable. Key features: - Configurable failure threshold, open duration, and half-open parameters - Thread-safe state transitions with atomic operations - State change callbacks for monitoring/metrics integration - Automatic transition from open to half-open after timeout Refs: #403
- Add circuit_breaker parameter to resilient_client constructor - Check circuit breaker before attempting send operations - Record success/failure to circuit breaker after operations - Add circuit_state(), reset_circuit(), set_circuit_state_callback() methods - Add circuit_open error code for fast-fail scenarios - Move circuit_breaker_config struct outside class to fix default initializer issue Refs: #403
Add 18 unit tests covering: - Basic state (closed, open, half-open) - State transitions and thresholds - Timeout-based transitions - State change callbacks - Reset functionality - Thread safety with concurrent operations - State to string conversion - Next attempt time validation Refs: #403
Add changelog entries for Circuit Breaker pattern implementation (#403): - English and Korean versions updated - Describes circuit_breaker class with three-state pattern - Lists all configuration parameters and API additions - Mentions resilient_client integration and test coverage
Contributor
Performance ComparisonBase Branch ResultsNo base results PR Branch ResultsNo PR results |
Add error_codes_ext namespace with circuit_open error code to the fallback block (when KCENON_WITH_COMMON_SYSTEM is not defined) in result_types.h for API compatibility. This fixes build failures when building without common_system dependency, where resilient_client.cpp references error_codes_ext which was only defined in the KCENON_WITH_COMMON_SYSTEM path.
Document the fix for error_codes_ext namespace missing in fallback build path. This fix ensures builds without common_system dependency compile correctly.
Contributor
Performance ComparisonBase Branch ResultsNo base results PR Branch ResultsNo PR results |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #420 +/- ##
==========================================
+ Coverage 32.94% 33.19% +0.24%
==========================================
Files 39 39
Lines 2841 2841
==========================================
+ Hits 936 943 +7
+ Misses 1905 1898 -7
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
kcenon
added a commit
that referenced
this pull request
Apr 13, 2026
…clients (#420) * feat(utils): implement circuit breaker pattern for fault tolerance Add circuit_breaker class with three-state machine (closed, open, half-open) to prevent cascade failures and provide fast-fail behavior when backend services are unavailable. Key features: - Configurable failure threshold, open duration, and half-open parameters - Thread-safe state transitions with atomic operations - State change callbacks for monitoring/metrics integration - Automatic transition from open to half-open after timeout Refs: #403 * feat(utils): integrate circuit breaker with resilient_client - Add circuit_breaker parameter to resilient_client constructor - Check circuit breaker before attempting send operations - Record success/failure to circuit breaker after operations - Add circuit_state(), reset_circuit(), set_circuit_state_callback() methods - Add circuit_open error code for fast-fail scenarios - Move circuit_breaker_config struct outside class to fix default initializer issue Refs: #403 * test(utils): add comprehensive circuit breaker unit tests Add 18 unit tests covering: - Basic state (closed, open, half-open) - State transitions and thresholds - Timeout-based transitions - State change callbacks - Reset functionality - Thread safety with concurrent operations - State to string conversion - Next attempt time validation Refs: #403 * docs(changelog): add circuit breaker implementation entry Add changelog entries for Circuit Breaker pattern implementation (#403): - English and Korean versions updated - Describes circuit_breaker class with three-state pattern - Lists all configuration parameters and API additions - Mentions resilient_client integration and test coverage * fix(utils): add error_codes_ext namespace to fallback build path Add error_codes_ext namespace with circuit_open error code to the fallback block (when KCENON_WITH_COMMON_SYSTEM is not defined) in result_types.h for API compatibility. This fixes build failures when building without common_system dependency, where resilient_client.cpp references error_codes_ext which was only defined in the KCENON_WITH_COMMON_SYSTEM path. * docs(changelog): add circuit breaker build fix entry Document the fix for error_codes_ext namespace missing in fallback build path. This fix ensures builds without common_system dependency compile correctly.
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.
Summary
circuit_breakerclass with three-state pattern (closed → open → half_open)resilient_clientfor automatic failure managementCloses #403
Changes
New Files
include/kcenon/network/utils/circuit_breaker.h- Circuit breaker header with state machine interfacesrc/utils/circuit_breaker.cpp- Thread-safe circuit breaker implementationtests/unit/test_circuit_breaker.cpp- 18 comprehensive unit testsModified Files
include/kcenon/network/utils/resilient_client.h- Add circuit breaker integration APIsrc/utils/resilient_client.cpp- Integrate circuit breaker with send/retry logicinclude/kcenon/network/utils/result_types.h- Addcircuit_openerror codeCMakeLists.txt- Add circuit_breaker.cpp to library sourcestests/CMakeLists.txt- Add circuit breaker test targetCHANGELOG.md/CHANGELOG_KO.md- Document new featureFeatures
failure_threshold- failures before opening circuitopen_duration- time before attempting half-openhalf_open_successes- successes needed to closehalf_open_max_calls- max calls during half-openTest plan