Skip to content

Recheck circuit state inside the recovery lock - #312

Merged
byroot merged 1 commit into
redis-rb:masterfrom
OskarEichler:codex/recheck-circuit-recovery
Aug 27, 2026
Merged

Recheck circuit state inside the recovery lock#312
byroot merged 1 commit into
redis-rb:masterfrom
OskarEichler:codex/recheck-circuit-recovery

Conversation

@OskarEichler

Copy link
Copy Markdown
Contributor

Summary

  • Recheck whether the circuit is still open after acquiring its recovery mutex.
  • Prevent a second waiting caller from reading an empty error history after the first caller closes the circuit.

Reproduction

On 0.30.1/master, create a breaker with error_threshold: 1, error_timeout: 0 and trigger one RedisClient::ConnectionError. Hold its @lock, start two threads calling breaker.protect { :success }, wait until both threads block on that mutex, then release it and join both with a deadline.

Before: one succeeds; the other raises NoMethodError on @errors.last < ....
After: both return :success.

Both callers observe the open state before waiting. The first clears the errors when closing; the second must check state again under the lock. This is separate from the already-merged error-window correction in #247.

Verification

  • Ruby 4.0.6, redis-client 0.30.1; temporary deterministic two-thread reproduction with bounded joins.
  • Existing circuit-breaker and pooled suites: 65 cases / 1,210 assertions, zero failures, errors, retries or skips on both baseline and patch.
  • Ruby syntax and whitespace checks pass.
  • Targeted current RuboCop passes excluding the pre-existing Style/EmptyClassDefinition offense on OpenCircuitError. No lint configuration changed.

Compatibility and limitations

No intended breaking changes, API changes, dependency changes or altered threshold policy. Other Ruby implementations and upstream CI are not yet locally verified. No test files added or modified, per the originating project's policy; the focused reproduction was run outside the repository.

Prepared with Codex assistance; findings and checks above were reproduced locally.

@byroot
byroot merged commit 3ac935f into redis-rb:master Aug 27, 2026
14 of 15 checks passed
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.

2 participants