diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-20 03:31:27 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-20 03:31:27 +0200 |
commit | 7c21a3de0adba015250d657e7605a228d5244009 (patch) | |
tree | a65527724e843681fc074f197265a5eb6126e263 | |
parent | 0a68c1ab175f8b45cb478e2a05732e1179efa0fb (diff) |
Fix race in lock pending
-rw-r--r-- | timers.go | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -20,7 +20,7 @@ import ( type Timer struct { timer *time.Timer - modifyingLock sync.Mutex + modifyingLock sync.RWMutex runningLock sync.Mutex isPending bool } @@ -67,6 +67,12 @@ func (timer *Timer) DelSync() { timer.runningLock.Unlock() } +func (timer *Timer) IsPending() bool { + timer.modifyingLock.RLock() + defer timer.modifyingLock.RUnlock() + return timer.isPending +} + func (peer *Peer) timersActive() bool { return peer.isRunning.Get() && peer.device != nil && peer.device.isUp.Get() && len(peer.device.peers.keyMap) > 0 } @@ -87,7 +93,7 @@ func expiredRetransmitHandshake(peer *Peer) { /* We set a timer for destroying any residue that might be left * of a partial exchange. */ - if peer.timersActive() && !peer.timers.zeroKeyMaterial.isPending { + if peer.timersActive() && !peer.timers.zeroKeyMaterial.IsPending() { peer.timers.zeroKeyMaterial.Mod(RejectAfterTime * 3) } } else { @@ -140,7 +146,7 @@ func expiredPersistentKeepalive(peer *Peer) { /* Should be called after an authenticated data packet is sent. */ func (peer *Peer) timersDataSent() { - if peer.timersActive() && !peer.timers.newHandshake.isPending { + if peer.timersActive() && !peer.timers.newHandshake.IsPending() { peer.timers.newHandshake.Mod(KeepaliveTimeout + RekeyTimeout) } } @@ -148,7 +154,7 @@ func (peer *Peer) timersDataSent() { /* Should be called after an authenticated data packet is received. */ func (peer *Peer) timersDataReceived() { if peer.timersActive() { - if !peer.timers.sendKeepalive.isPending { + if !peer.timers.sendKeepalive.IsPending() { peer.timers.sendKeepalive.Mod(KeepaliveTimeout) } else { peer.timers.needAnotherKeepalive = true |