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

p2p: re-check after sleeps #2664

Merged
merged 13 commits into from Nov 11, 2018
12 changes: 10 additions & 2 deletions p2p/switch.go
Expand Up @@ -328,6 +328,11 @@ func (sw *Switch) reconnectToPeer(addr *NetAddress) {
return
}

if sw.IsDialingOrExistingAddress(addr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks. These changes are partial fixes for #2716.

Note the races are still possible, but this should help significantly. We'll likely have to rearchitect the code a bit to solve this fully.

Thanks!

sw.Logger.Debug("Peer connection has been established or dialed while we waiting next try", "addr", addr)
return
}

err := sw.DialPeerWithAddress(addr, true)
if err == nil {
return // success
Expand Down Expand Up @@ -415,12 +420,15 @@ func (sw *Switch) DialPeersAsync(addrBook AddrBook, peers []string, persistent b
if addr.Same(ourAddr) {
sw.Logger.Debug("Ignore attempt to connect to ourselves", "addr", addr, "ourAddr", ourAddr)
return
} else if sw.IsDialingOrExistingAddress(addr) {
}

sw.randomSleep(0)

if sw.IsDialingOrExistingAddress(addr) {
sw.Logger.Debug("Ignore attempt to connect to an existing peer", "addr", addr)
return
}

sw.randomSleep(0)
err := sw.DialPeerWithAddress(addr, persistent)
if err != nil {
switch err.(type) {
Expand Down