replace Peer.ForEachConnection with Peer.Connections
The former is prone to triggering deadlocks since the lock is held on the peer during the iteration.
This commit is contained in:
1 parent
08a08be370
commit
d5eb76f32e
6 files changed
+19
-24
No files matched your search
+3
-2
@@ -140,17 +140,18 @@ func (routes *Routes) calculateBroadcast() map[PeerName][]PeerName {
|
||||
// This is rather similar to the inner loop on
|
||||
// peer.Routes(...); the main difference is in the
|
||||
// locking.
|
||||
ourself.ForEachConnection(func(remoteName PeerName, conn Connection) {
|
||||
for _, conn := range ourself.Connections() {
|
||||
if !conn.Established() {
|
||||
return
|
||||
}
|
||||
remoteName := conn.Remote().Name
|
||||
if _, found := reached[remoteName]; found {
|
||||
return
|
||||
}
|
||||
if remoteConn, found := conn.Remote().ConnectionTo(ourself.Name); found && remoteConn.Established() {
|
||||
hops = append(hops, remoteName)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
broadcast[name] = hops
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user