summaryrefslogtreecommitdiffhomepage
path: root/device/timers.go
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josh@tailscale.com>2020-12-15 17:44:21 -0800
committerJason A. Donenfeld <Jason@zx2c4.com>2021-01-07 14:49:44 +0100
commitf7bbdc31a0065e3d5a68a3e6c7a7449954fdd339 (patch)
treeb2605ff0dd0a12be4055d8b936abdb666a88ae9a /device/timers.go
parent70861686d3005de91b45d38e5b16fd3132a4a872 (diff)
device: fix data race in peer.timersActive
Found by the race detector and existing tests. To avoid introducing a lock into this hot path, calculate and cache whether any peers exist. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
Diffstat (limited to 'device/timers.go')
-rw-r--r--device/timers.go2
1 files changed, 1 insertions, 1 deletions
diff --git a/device/timers.go b/device/timers.go
index e94da36..dbd4c66 100644
--- a/device/timers.go
+++ b/device/timers.go
@@ -73,7 +73,7 @@ func (timer *Timer) IsPending() bool {
}
func (peer *Peer) timersActive() bool {
- return peer.isRunning.Get() && peer.device != nil && peer.device.isUp.Get() && len(peer.device.peers.keyMap) > 0
+ return peer.isRunning.Get() && peer.device != nil && peer.device.isUp.Get() && !peer.device.peers.empty.Get()
}
func expiredRetransmitHandshake(peer *Peer) {