-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: networking: call Stream.CloseWrite right after writing #9892
Conversation
@hanabi1224 Thanks for the contribution! @magik6k has a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
This seems to be more about the client side being nice / more correct. Reading cborrpc isn't like ReadAll, it will stop after the cbor object is fully read.
Change looks good, other than missing error check.
chain/exchange/client.go
Outdated
@@ -430,6 +430,7 @@ func (c *client) sendRequestToPeer(ctx context.Context, peer peer.ID, req *Reque | |||
} | |||
_ = stream.SetWriteDeadline(time.Time{}) // clear deadline // FIXME: Needs | |||
// its own API (https://github.com/libp2p/go-libp2p/core/issues/162). | |||
stream.CloseWrite() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lint fails due to missing error check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Related Issues
It fixes potential deadlock in
Hello
andChainExchange
p2p protocols. Below example is a minimal repro, although currently in the actual lotus code the cbor decoder will either succeed or fail fast before deadlock happens, IMHO it's a nice improvement to have.CloseWrite
sends aFIN
header overyamux
which notifies the reader side that stream writing has finished.If the
stream.CloseWrite()
line in the below example is commented out, it will deadlock.to run the program
main.go
go mod tidy
go mod vendor
go run .
Output with
CloseWrite
:Output without
CloseWrite
:Proposed Changes
Additional Info
Checklist
Before you mark the PR ready for review, please make sure that:
<PR type>: <area>: <change being made>
fix: mempool: Introduce a cache for valid signatures
PR type
: fix, feat, build, chore, ci, docs, perf, refactor, revert, style, testarea
, e.g. api, chain, state, market, mempool, multisig, networking, paych, proving, sealing, wallet, deps