From 1d001314168755e0cbed369cfc830b4d7535c056 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 8 Oct 2018 22:09:55 +0100 Subject: [PATCH] Hopefully fix a concurrent map read-write when removing peers --- src/yggdrasil/peer.go | 2 +- src/yggdrasil/switch.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/yggdrasil/peer.go b/src/yggdrasil/peer.go index f0dd3d0..5095cdd 100644 --- a/src/yggdrasil/peer.go +++ b/src/yggdrasil/peer.go @@ -127,7 +127,7 @@ func (ps *peers) removePeer(port switchPort) { return } // Can't remove self peer ps.core.router.doAdmin(func() { - ps.core.switchTable.unlockedRemovePeer(port) + ps.core.switchTable.forgetPeer(port) }) ps.mutex.Lock() oldPorts := ps.getPorts() diff --git a/src/yggdrasil/switch.go b/src/yggdrasil/switch.go index d6e981e..72f17ed 100644 --- a/src/yggdrasil/switch.go +++ b/src/yggdrasil/switch.go @@ -242,7 +242,9 @@ func (t *switchTable) cleanRoot() { // Removes a peer. // 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. -func (t *switchTable) unlockedRemovePeer(port switchPort) { +func (t *switchTable) forgetPeer(port switchPort) { + t.mutex.Lock() + defer t.mutex.Unlock() delete(t.data.peers, port) t.updater.Store(&sync.Once{}) if port != t.parent {