Skip to content
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(dot/network): implement a handshake timeout #1615

Merged
merged 14 commits into from
Jun 3, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions dot/network/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,20 +234,20 @@ func (s *Service) sendData(peer peer.ID, hs Handshake, info *notificationsProtoc
return
}

hsTicker := time.NewTicker(handshakeTimeout)
hsTimer := time.NewTimer(handshakeTimeout)
var hs Handshake
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also do

defer hsTimer.Stop()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!


select {
case <-hsTicker.C:
hsTicker.Stop()
case <-hsTimer.C:
hsTimer.Stop()

logger.Warn("handshake timeout reached", "protocol", info.protocolID, "peer", peer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to trace

_ = stream.Close()
info.outboundHandshakeData.Delete(peer)
return

case hsResponse := <-s.readHandshake(stream, decodeBlockAnnounceHandshake):
hsTicker.Stop()
hsTimer.Stop()

if hsResponse.err != nil {
logger.Trace("failed to read handshake", "protocol", info.protocolID, "peer", peer, "error", err)
Expand Down Expand Up @@ -321,7 +321,7 @@ func (s *Service) broadcastExcluding(info *notificationsProtocol, excluding peer
}

func (s *Service) readHandshake(stream libp2pnetwork.Stream, decoder HandshakeDecoder) <-chan *handshakeReader {
hsC := make(chan *handshakeReader, 1)
hsC := make(chan *handshakeReader)

go func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we close hsC on errors?

msgBytes := s.bufPool.get()
Expand Down