-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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: solve potential deadlock for bsc p2p protocol handshake #1479
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package bsc | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"time" | ||
|
||
|
@@ -11,6 +12,17 @@ import ( | |
"github.com/ethereum/go-ethereum/p2p/enr" | ||
) | ||
|
||
const ( | ||
// handshakeWaitTimeout is the maximum allowed time for the extension waiting to | ||
// complete handshake before dropping the connection as malicious. | ||
handshakeWaitTimeout = 20 * time.Second | ||
) | ||
|
||
var ( | ||
// errHandshakeWaitTimeout is returned if a peer waits handshake for too long | ||
errHandshakeWaitTimeout = errors.New("peer handshake wait timeout") | ||
) | ||
|
||
// Handler is a callback to invoke from an outside runner after the boilerplate | ||
// exchanges have passed. | ||
type Handler func(peer *Peer) error | ||
|
@@ -74,6 +86,11 @@ func MakeProtocols(backend Backend, dnsdisc enode.Iterator) []p2p.Protocol { | |
// Handle is the callback invoked to manage the life cycle of a `bsc` peer. | ||
// When this function terminates, the peer is disconnected. | ||
func Handle(backend Backend, peer *Peer) error { | ||
select { | ||
case <-peer.handshaked: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems not extensible, as the channel is only used by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. snap has no handshake, it's easy. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
another sub protocol need handshake should have it's own |
||
case <-time.After(handshakeWaitTimeout): | ||
return errHandshakeWaitTimeout | ||
} | ||
for { | ||
if err := handleMessage(backend, peer); err != nil { | ||
peer.Log().Debug("Message handling failed in `bsc`", "err", err) | ||
|
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.
Does this seem against the design of
geth
, as if every protocol follow the same pattern, the handshake of the different protocol will happen serially.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.
the design of geth has no handshake exclude eth protocol,
waitBscExtension and registerBscExtension can end quickly
when handshake of sub protocol involved in above two , it' begin to slow down and lead to problem