diff --git a/infrastructure/network/connmanager/connection_requests.go b/infrastructure/network/connmanager/connection_requests.go index 720a95688..c01613678 100644 --- a/infrastructure/network/connmanager/connection_requests.go +++ b/infrastructure/network/connmanager/connection_requests.go @@ -63,6 +63,7 @@ func (c *ConnectionManager) checkRequestedConnections(connSet connectionSet) { } // try to initiate connection + log.Debugf("Connecting to connection request %s", connReq.address) err := c.initiateConnection(connReq.address) if err != nil { log.Infof("Couldn't connect to %s: %s", address, err) diff --git a/infrastructure/network/connmanager/connmanager.go b/infrastructure/network/connmanager/connmanager.go index 8930219c0..33c74c8f1 100644 --- a/infrastructure/network/connmanager/connmanager.go +++ b/infrastructure/network/connmanager/connmanager.go @@ -143,3 +143,19 @@ func (c *ConnectionManager) waitTillNextIteration() { case <-c.loopTicker.C: } } + +func (c *ConnectionManager) connectionExists(addressString string) bool { + if _, ok := c.activeRequested[addressString]; ok { + return true + } + + if _, ok := c.activeOutgoing[addressString]; ok { + return true + } + + if _, ok := c.activeIncoming[addressString]; ok { + return true + } + + return false +} diff --git a/infrastructure/network/connmanager/outgoing_connections.go b/infrastructure/network/connmanager/outgoing_connections.go index 873239cdc..e9a3bf0fd 100644 --- a/infrastructure/network/connmanager/outgoing_connections.go +++ b/infrastructure/network/connmanager/outgoing_connections.go @@ -39,6 +39,12 @@ func (c *ConnectionManager) checkOutgoingConnections(connSet connectionSet) { netAddress := address.NetAddress() tcpAddress := netAddress.TCPAddress() addressString := tcpAddress.String() + + if c.connectionExists(addressString) { + log.Debugf("Fetched address %s from address manager but it's already connected. Skipping...", addressString) + continue + } + isBanned, err := c.addressManager.IsBanned(netAddress) if err != nil { log.Infof("Couldn't resolve whether %s is banned: %s", addressString, err) @@ -49,6 +55,8 @@ func (c *ConnectionManager) checkOutgoingConnections(connSet connectionSet) { } c.addressManager.Attempt(netAddress) + log.Debugf("Connecting to %s because we have %d outgoing connections and the target is "+ + "%d", addressString, len(c.activeOutgoing), c.targetOutgoing) err = c.initiateConnection(addressString) if err != nil { log.Infof("Couldn't connect to %s: %s", addressString, err) diff --git a/infrastructure/network/netadapter/server/grpcserver/grpc_connection.go b/infrastructure/network/netadapter/server/grpcserver/grpc_connection.go index af145fffb..7f2d3e42d 100644 --- a/infrastructure/network/netadapter/server/grpcserver/grpc_connection.go +++ b/infrastructure/network/netadapter/server/grpcserver/grpc_connection.go @@ -53,7 +53,7 @@ func (c *gRPCConnection) Start(router *router.Router) { spawn("gRPCConnection.Start-connectionLoops", func() { err := c.connectionLoops() if err != nil { - log.Errorf("error from connectionLoops for %s: %+v", c.address, err) + log.Errorf("error from connectionLoops for %s: %s", c.address, err) } }) }