fix(async/unstable): circuit breaker stale openedAt and duplicate callbacks#7097
fix(async/unstable): circuit breaker stale openedAt and duplicate callbacks#7097bartlomieju merged 6 commits intodenoland:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7097 +/- ##
==========================================
- Coverage 94.43% 94.42% -0.01%
==========================================
Files 630 630
Lines 50566 50566
Branches 8969 8973 +4
==========================================
- Hits 47750 47749 -1
Misses 2247 2247
- Partials 569 570 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
bartlomieju
left a comment
There was a problem hiding this comment.
LGTM — both bug fixes are real and correctly addressed.
Stale openedAt: currentTime was captured at the top of execute() and passed into #handleFailure as openedAt. If fn() is slow, the cooldown starts from the past. Using Date.now() at failure time is the right fix.
Duplicate callbacks: When halfOpenMaxConcurrent > 1 and multiple requests fail concurrently, each #handleFailure call saw previousState === "half_open" and fired onStateChange/onOpen. Checking the current state to gate callbacks and preserving the existing openedAt is correct.
The tryCall extraction is clean. One subtlety: it only wraps the predicate, not #handleFailure (which the old try/catch did), but that's fine since #handleFailure can't throw — all callbacks go through safeCallback.
Nit: the @returns void tags on forceOpen, forceClose, reset are unnecessary — void return is self-evident from the signature.
tryCallhelper to simplify predicate error handling