diff options
author | Josh Bleecher Snyder <josh@tailscale.com> | 2020-12-14 15:28:52 -0800 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-01-07 14:49:44 +0100 |
commit | 63066ce4062a85224821ce302e3eb8c34e95a658 (patch) | |
tree | f6945216e1b48bc5404f612cdcc5564b12e93aae /device/timers.go | |
parent | e1fa1cc5560020e67d33aa7e74674853671cf0a0 (diff) |
device: fix persistent_keepalive_interval data races
Co-authored-by: David Anderson <danderson@tailscale.com>
Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
Diffstat (limited to 'device/timers.go')
-rw-r--r-- | device/timers.go | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/device/timers.go b/device/timers.go index 48cef94..e94da36 100644 --- a/device/timers.go +++ b/device/timers.go @@ -138,7 +138,7 @@ func expiredZeroKeyMaterial(peer *Peer) { } func expiredPersistentKeepalive(peer *Peer) { - if peer.persistentKeepaliveInterval > 0 { + if atomic.LoadUint32(&peer.persistentKeepaliveInterval) > 0 { peer.SendKeepalive() } } @@ -201,8 +201,9 @@ func (peer *Peer) timersSessionDerived() { /* Should be called before a packet with authentication -- keepalive, data, or handshake -- is sent, or after one is received. */ func (peer *Peer) timersAnyAuthenticatedPacketTraversal() { - if peer.persistentKeepaliveInterval > 0 && peer.timersActive() { - peer.timers.persistentKeepalive.Mod(time.Duration(peer.persistentKeepaliveInterval) * time.Second) + keepalive := atomic.LoadUint32(&peer.persistentKeepaliveInterval) + if keepalive > 0 && peer.timersActive() { + peer.timers.persistentKeepalive.Mod(time.Duration(keepalive) * time.Second) } } |