From ace50a0529bdd69f32f637ee84845bde45de07b6 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 27 Jan 2021 15:53:21 +0100 Subject: device: avoid deadlock when changing private key and removing self peers Signed-off-by: Jason A. Donenfeld --- device/device.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/device/device.go b/device/device.go index 47c4944..e769a20 100644 --- a/device/device.go +++ b/device/device.go @@ -268,7 +268,9 @@ func (device *Device) SetPrivateKey(sk NoisePrivateKey) error { publicKey := sk.publicKey() for key, peer := range device.peers.keyMap { if peer.handshake.remoteStatic.Equals(publicKey) { + peer.handshake.mutex.RUnlock() unsafeRemovePeer(device, peer, key) + peer.handshake.mutex.RLock() } } -- cgit v1.2.3