Fix deadlock when closing iterator while Next blocks on I/O#1137
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
6ecebaa to
c224d79
Compare
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>
c224d79 to
5a319dd
Compare
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.
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.