Commit 3ab2f7a9 authored by Petar Radovic's avatar Petar Radovic Committed by GitHub

move peer registty lock on disconnect before handler (#322)

parent ec83fd1d
...@@ -47,11 +47,11 @@ func (r *peerRegistry) Disconnected(_ network.Network, c network.Conn) { ...@@ -47,11 +47,11 @@ func (r *peerRegistry) Disconnected(_ network.Network, c network.Conn) {
peerID := c.RemotePeer() peerID := c.RemotePeer()
r.mu.Lock() r.mu.Lock()
defer r.mu.Unlock()
// remove only the related connection, // remove only the related connection,
// not eventually newly created one for the same peer // not eventually newly created one for the same peer
if _, ok := r.connections[peerID][c]; !ok { if _, ok := r.connections[peerID][c]; !ok {
r.mu.Unlock()
return return
} }
...@@ -63,6 +63,8 @@ func (r *peerRegistry) Disconnected(_ network.Network, c network.Conn) { ...@@ -63,6 +63,8 @@ func (r *peerRegistry) Disconnected(_ network.Network, c network.Conn) {
if len(r.connections[peerID]) == 0 { if len(r.connections[peerID]) == 0 {
delete(r.connections, peerID) delete(r.connections, peerID)
} }
r.mu.Unlock()
if r.disconnecter != nil { if r.disconnecter != nil {
r.disconnecter.Disconnected(overlay) r.disconnecter.Disconnected(overlay)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment