Browse Source

p2p: dial addrs which came from seed instead of calling ensurePeers (#3762)

Calling ensurePeers outside of ensurePeersRoutine can lead to nodes
disconnecting from us due to "sent next PEX request too soon" error.

Solution is to just dial addrs we got from src instead of calling
ensurePeers.

Refs #2093

Fixes #3338
pull/3772/head
Anton Kaliaev 6 years ago
committed by GitHub
parent
commit
d041476819
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 5 deletions
  1. +2
    -0
      CHANGELOG_PENDING.md
  2. +24
    -5
      p2p/pex/pex_reactor.go

+ 2
- 0
CHANGELOG_PENDING.md View File

@ -31,3 +31,5 @@ program](https://hackerone.com/tendermint).
- [rpc] \#3700 Make possible to set absolute paths for TLS cert and key (@climber73)
### BUG FIXES:
- [p2p] \#3338 Prevent "sent next PEX request too soon" errors by not calling
ensurePeers outside of ensurePeersRoutine

+ 24
- 5
p2p/pex/pex_reactor.go View File

@ -340,6 +340,15 @@ func (r *PEXReactor) ReceiveAddrs(addrs []*p2p.NetAddress, src Peer) error {
if err != nil {
return err
}
srcIsSeed := false
for _, seedAddr := range r.seedAddrs {
if seedAddr.Equals(srcAddr) {
srcIsSeed = true
break
}
}
for _, netAddr := range addrs {
// Validate netAddr. Disconnect from a peer if it sends us invalid data.
if netAddr == nil {
@ -365,13 +374,23 @@ func (r *PEXReactor) ReceiveAddrs(addrs []*p2p.NetAddress, src Peer) error {
}
// If this address came from a seed node, try to connect to it without
// waiting.
for _, seedAddr := range r.seedAddrs {
if seedAddr.Equals(srcAddr) {
r.ensurePeers()
}
// waiting (#2093)
if srcIsSeed {
r.Logger.Info("Will dial address, which came from seed", "addr", netAddr, "seed", srcAddr)
go func(addr *p2p.NetAddress) {
err := r.dialPeer(addr)
if err != nil {
switch err.(type) {
case errMaxAttemptsToDial, errTooEarlyToDial:
r.Logger.Debug(err.Error(), "addr", addr)
default:
r.Logger.Error(err.Error(), "addr", addr)
}
}
}(netAddr)
}
}
return nil
}


Loading…
Cancel
Save