Skip to content

fix(async/unstable): circuit breaker stale openedAt and duplicate callbacks#7097

Merged
bartlomieju merged 6 commits intodenoland:mainfrom
tomas-zijdemans:cb-ready
Apr 21, 2026
Merged

fix(async/unstable): circuit breaker stale openedAt and duplicate callbacks#7097
bartlomieju merged 6 commits intodenoland:mainfrom
tomas-zijdemans:cb-ready

Conversation

@tomas-zijdemans
Copy link
Copy Markdown
Contributor

  • Fix cooldown timer bypassed when wrapped function is slow
  • Fix duplicate callbacks on concurrent half-open failures
  • Extract tryCall helper to simplify predicate error handling
  • Improve JSDoc and add test for synchronous throws

@github-actions github-actions Bot added the async label Apr 14, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.42%. Comparing base (a3a6ef6) to head (226dff4).
⚠️ Report is 5 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bartlomieju bartlomieju merged commit afdb824 into denoland:main Apr 21, 2026
32 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants