diff --git a/infrastructure/network/connmanager/connection_requests.go b/infrastructure/network/connmanager/connection_requests.go index c0615fa11..720a95688 100644 --- a/infrastructure/network/connmanager/connection_requests.go +++ b/infrastructure/network/connmanager/connection_requests.go @@ -89,22 +89,24 @@ func (c *ConnectionManager) AddConnectionRequest(address string, isPermanent boo // spawn goroutine so that caller doesn't wait in case connectionManager is in the midst of handling // connection requests spawn("ConnectionManager.AddConnectionRequest", func() { - c.connectionRequestsLock.Lock() - defer c.connectionRequestsLock.Unlock() - - if _, ok := c.activeRequested[address]; ok { - return - } - - c.pendingRequested[address] = &connectionRequest{ - address: address, - isPermanent: isPermanent, - } - + c.addConnectionRequest(address, isPermanent) c.run() }) } +func (c *ConnectionManager) addConnectionRequest(address string, isPermanent bool) { + c.connectionRequestsLock.Lock() + defer c.connectionRequestsLock.Unlock() + if _, ok := c.activeRequested[address]; ok { + return + } + + c.pendingRequested[address] = &connectionRequest{ + address: address, + isPermanent: isPermanent, + } +} + // RemoveConnection disconnects the connection for the given address // and removes it entirely from the connection manager. func (c *ConnectionManager) RemoveConnection(address string) {