5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-22 20:00:27 +00:00

Hopefully fix a concurrent map read-write when removing peers

This commit is contained in:
Neil Alexander 2018-10-08 22:09:55 +01:00
parent 401960e17e
commit 1d00131416
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
2 changed files with 4 additions and 2 deletions

View File

@ -127,7 +127,7 @@ func (ps *peers) removePeer(port switchPort) {
return return
} // Can't remove self peer } // Can't remove self peer
ps.core.router.doAdmin(func() { ps.core.router.doAdmin(func() {
ps.core.switchTable.unlockedRemovePeer(port) ps.core.switchTable.forgetPeer(port)
}) })
ps.mutex.Lock() ps.mutex.Lock()
oldPorts := ps.getPorts() oldPorts := ps.getPorts()

View File

@ -242,7 +242,9 @@ func (t *switchTable) cleanRoot() {
// Removes a peer. // Removes a peer.
// Must be called by the router mainLoop goroutine, e.g. call router.doAdmin with a lambda that calls this. // Must be called by the router mainLoop goroutine, e.g. call router.doAdmin with a lambda that calls this.
// If the removed peer was this node's parent, it immediately tries to find a new parent. // If the removed peer was this node's parent, it immediately tries to find a new parent.
func (t *switchTable) unlockedRemovePeer(port switchPort) { func (t *switchTable) forgetPeer(port switchPort) {
t.mutex.Lock()
defer t.mutex.Unlock()
delete(t.data.peers, port) delete(t.data.peers, port)
t.updater.Store(&sync.Once{}) t.updater.Store(&sync.Once{})
if port != t.parent { if port != t.parent {