only call dial waker on errors that should cause new dial

This commit is contained in:
William Banfield
2022-06-21 16:50:57 -04:00
parent cfd13825e2
commit 714d58ed98
2 changed files with 3 additions and 1 deletions

View File

@@ -649,9 +649,11 @@ func (m *PeerManager) Dialed(address NodeAddress) error {
}
}
if address.NodeID == m.selfID {
m.dialWaker.Wake()
return fmt.Errorf("rejecting connection to self (%v)", address.NodeID)
}
if m.isConnected(address.NodeID) {
m.dialWaker.Wake()
return fmt.Errorf("peer %v is already connected", address.NodeID)
}
if m.options.MaxConnected > 0 && len(m.connected) >= int(m.options.MaxConnected) {
@@ -662,6 +664,7 @@ func (m *PeerManager) Dialed(address NodeAddress) error {
peer, ok := m.store.Get(address.NodeID)
if !ok {
m.dialWaker.Wake()
return fmt.Errorf("peer %q was removed while dialing", address.NodeID)
}
now := time.Now().UTC()

View File

@@ -634,7 +634,6 @@ func (r *Router) connectPeer(ctx context.Context, address NodeAddress) {
if err := r.runWithPeerMutex(func() error { return r.peerManager.Dialed(address) }); err != nil {
r.logger.Error("failed to dial peer", "op", "outgoing/dialing", "peer", address.NodeID, "err", err)
r.peerManager.dialWaker.Wake()
conn.Close()
return
}