Skip to content

Fix deadlock when closing iterator while Next blocks on I/O#1137

Merged
flimzy merged 1 commit intomainfrom
changesDeadlock
Feb 7, 2026
Merged

Fix deadlock when closing iterator while Next blocks on I/O#1137
flimzy merged 1 commit intomainfrom
changesDeadlock

Conversation

@flimzy
Copy link
Member

@flimzy flimzy commented Feb 6, 2026

Close now cancels the context and closes the feed before acquiring the mutex, so a blocked Next call can be interrupted and release the lock.

@codecov
Copy link

codecov bot commented Feb 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.17%. Comparing base (7df27a7) to head (5a319dd).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1137      +/-   ##
==========================================
+ Coverage   63.15%   63.17%   +0.02%     
==========================================
  Files         290      290              
  Lines       19975    19986      +11     
==========================================
+ Hits        12615    12627      +12     
  Misses       6808     6808              
+ Partials      552      551       -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.

Close() needs the mutex to cancel the context and close the feed, but
Next() holds the mutex while blocked in feed.Next() waiting on network
I/O. Break the deadlock by calling cancel() and feed.Close() before
acquiring the mutex in Close().

Use an atomic closing flag checked in closeErr() to suppress spurious
errors (e.g. context.Canceled) that arise when Close() interrupts a
blocked feed — covering both the next() and awaitDone code paths.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@flimzy flimzy merged commit cde5469 into main Feb 7, 2026
18 checks passed
@flimzy flimzy deleted the changesDeadlock branch February 7, 2026 01:31
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.

1 participant