device: avoid deadlock when changing private key and removing self peers

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2021-01-27 15:53:21 +01:00
parent 8cc99631d0
commit ace50a0529

View file

@ -268,7 +268,9 @@ func (device *Device) SetPrivateKey(sk NoisePrivateKey) error {
publicKey := sk.publicKey() publicKey := sk.publicKey()
for key, peer := range device.peers.keyMap { for key, peer := range device.peers.keyMap {
if peer.handshake.remoteStatic.Equals(publicKey) { if peer.handshake.remoteStatic.Equals(publicKey) {
peer.handshake.mutex.RUnlock()
unsafeRemovePeer(device, peer, key) unsafeRemovePeer(device, peer, key)
peer.handshake.mutex.RLock()
} }
} }