[NOD-1285] Fix deadlock on connection manager (#880)

This commit is contained in:
Ori Newman 2020-08-19 13:24:20 +03:00 committed by GitHub
parent 8dd409dc1c
commit 8dae378bd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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) {