fix race from mutex that wasn't held long enough

This commit is contained in:
Arceliar 2021-09-23 04:35:31 -05:00
parent 529a33034b
commit 86e5306eec

View File

@ -129,6 +129,7 @@ func (k *keyStore) sendToSubnet(subnet address.Subnet, bs []byte) {
func (k *keyStore) update(key ed25519.PublicKey) *keyInfo { func (k *keyStore) update(key ed25519.PublicKey) *keyInfo {
k.mutex.Lock() k.mutex.Lock()
defer k.mutex.Unlock()
var kArray keyArray var kArray keyArray
copy(kArray[:], key) copy(kArray[:], key)
var info *keyInfo var info *keyInfo
@ -140,8 +141,6 @@ func (k *keyStore) update(key ed25519.PublicKey) *keyInfo {
k.keyToInfo[info.key] = info k.keyToInfo[info.key] = info
k.addrToInfo[info.address] = info k.addrToInfo[info.address] = info
k.subnetToInfo[info.subnet] = info k.subnetToInfo[info.subnet] = info
k.resetTimeout(info)
k.mutex.Unlock()
if buf := k.addrBuffer[info.address]; buf != nil { if buf := k.addrBuffer[info.address]; buf != nil {
k.core.WriteTo(buf.packet, iwt.Addr(info.key[:])) k.core.WriteTo(buf.packet, iwt.Addr(info.key[:]))
delete(k.addrBuffer, info.address) 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[:])) k.core.WriteTo(buf.packet, iwt.Addr(info.key[:]))
delete(k.subnetBuffer, info.subnet) delete(k.subnetBuffer, info.subnet)
} }
} else {
k.resetTimeout(info)
k.mutex.Unlock()
} }
k.resetTimeout(info)
return info return info
} }