fix(bitswap/network): stream.Close() blocks indefinitely on unresponsive peers#1083
Merged
fix(bitswap/network): stream.Close() blocks indefinitely on unresponsive peers#1083
stream.Close() blocks indefinitely on unresponsive peers#1083Conversation
stream.Close() blocks indefinitely on unresponsive peers
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #1083 +/- ##
==========================================
+ Coverage 61.08% 61.11% +0.02%
==========================================
Files 264 264
Lines 26225 26227 +2
==========================================
+ Hits 16020 16028 +8
+ Misses 8525 8520 -5
+ Partials 1680 1679 -1
... and 9 files with indirect coverage changes 🚀 New features to boost your workflow:
|
…t blocking SendMessage() can block indefinitely when the remote peer is slow or unresponsive during the multistream-select handshake completion. The fix sets a read deadline (using the calculated send timeout) before calling stream.Close(), ensuring the operation will time out rather than block indefinitely. See: multiformats/go-multistream#47 See: ipshipyard/waterworks-infra#860
006ef85 to
9937acb
Compare
gammazero
approved these changes
Jan 7, 2026
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.
Problem
SendMessage()in bitswap can block indefinitely when the remote peer is unresponsive, causing goroutine leaks. Over time, this exhausts worker goroutines and bitswap stops serving blocks entirely.Symptoms observed on production nodes:
vole bitswap checkreturnsResponded: false)Root cause(?): When lazy multistream-select is used,
stream.Close()must complete the protocol handshake read. If the peer doesn't respond (network issues, overloaded, unclean disconnect),ReadNextToken()blocks forever with no deadline.Fix
Set a read deadline before calling
stream.Close()inSendMessage():This ensures Close() times out instead of blocking indefinitely.
Related
stream.Close()blocks indefinitely on unresponsive peers libp2p/go-libp2p#3448Note
This PR is a localized fix for bitswap that can be shipped independently from the go-libp2p fix (defense in depth).