Fix race conditions in EWMA calculation and half-open state transitions#19
Draft
Fix race conditions in EWMA calculation and half-open state transitions#19
Conversation
- Fix EWMA breaker race condition using CAS loop for atomic EWMA updates - Fix half-open state to properly limit concurrent calls to ~1 - Add comprehensive concurrency tests Co-authored-by: costela <94699+costela@users.noreply.github.com>
- Replace recursion with loop in stateForCall to avoid potential stack overflow - Clarify comments about window swap timing Co-authored-by: costela <94699+costela@users.noreply.github.com>
- Fix percentage symbol in test assertion message - Improve comment clarity in window swap logic Co-authored-by: costela <94699+costela@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Identify significant issues in circuit breaker implementation
Fix race conditions in EWMA calculation and half-open state transitions
Nov 23, 2025
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.
Two concurrency bugs could prevent circuits from opening correctly or allow thundering herds during recovery.
Issues
EWMABreaker race condition: Concurrent observations read raw values (0.0/1.0) instead of the actual EWMA due to non-atomic read-modify-write:
Half-open state: Multiple goroutines could simultaneously transition from half-open and all pass through, violating the "~1 call" limit.
Changes
Verified with race detector and stress tests showing consistent max 1 concurrent call in half-open state.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.