Merge pull request #1638 from aboch/ovlk
Do not hold the peer map lock during the peerDBNetworkWalk
This commit is contained in:
commit
82a40d732f
1 changed files with 9 additions and 5 deletions
|
@ -80,25 +80,29 @@ func (d *driver) peerDbWalk(f func(string, *peerKey, *peerEntry) bool) error {
|
|||
func (d *driver) peerDbNetworkWalk(nid string, f func(*peerKey, *peerEntry) bool) error {
|
||||
d.peerDb.Lock()
|
||||
pMap, ok := d.peerDb.mp[nid]
|
||||
d.peerDb.Unlock()
|
||||
|
||||
if !ok {
|
||||
d.peerDb.Unlock()
|
||||
return nil
|
||||
}
|
||||
d.peerDb.Unlock()
|
||||
|
||||
mp := map[string]peerEntry{}
|
||||
|
||||
pMap.Lock()
|
||||
for pKeyStr, pEntry := range pMap.mp {
|
||||
mp[pKeyStr] = pEntry
|
||||
}
|
||||
pMap.Unlock()
|
||||
|
||||
for pKeyStr, pEntry := range mp {
|
||||
var pKey peerKey
|
||||
if _, err := fmt.Sscan(pKeyStr, &pKey); err != nil {
|
||||
logrus.Warnf("Peer key scan on network %s failed: %v", nid, err)
|
||||
}
|
||||
|
||||
if f(&pKey, &pEntry) {
|
||||
pMap.Unlock()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
pMap.Unlock()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue