fix(bitswap/network): stream.Close() blocks indefinitely on unresponsive peers
#1083
+106
−9
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).