From 86e5306eec42324a7e68b4a5e37b7b9d89e98c83 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Thu, 23 Sep 2021 04:35:31 -0500 Subject: [PATCH] fix race from mutex that wasn't held long enough --- src/ipv6rwc/ipv6rwc.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/ipv6rwc/ipv6rwc.go b/src/ipv6rwc/ipv6rwc.go index 1c715f0f..f71c638e 100644 --- a/src/ipv6rwc/ipv6rwc.go +++ b/src/ipv6rwc/ipv6rwc.go @@ -129,6 +129,7 @@ func (k *keyStore) sendToSubnet(subnet address.Subnet, bs []byte) { func (k *keyStore) update(key ed25519.PublicKey) *keyInfo { k.mutex.Lock() + defer k.mutex.Unlock() var kArray keyArray copy(kArray[:], key) var info *keyInfo @@ -140,8 +141,6 @@ func (k *keyStore) update(key ed25519.PublicKey) *keyInfo { k.keyToInfo[info.key] = info k.addrToInfo[info.address] = info k.subnetToInfo[info.subnet] = info - k.resetTimeout(info) - k.mutex.Unlock() if buf := k.addrBuffer[info.address]; buf != nil { k.core.WriteTo(buf.packet, iwt.Addr(info.key[:])) delete(k.addrBuffer, info.address) @@ -150,10 +149,8 @@ func (k *keyStore) update(key ed25519.PublicKey) *keyInfo { k.core.WriteTo(buf.packet, iwt.Addr(info.key[:])) delete(k.subnetBuffer, info.subnet) } - } else { - k.resetTimeout(info) - k.mutex.Unlock() } + k.resetTimeout(info) return info }