aboutsummaryrefslogtreecommitdiffstats
path: root/device/peer.go
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josh@tailscale.com>2020-12-18 16:32:46 -0800
committerJason A. Donenfeld <Jason@zx2c4.com>2021-01-07 14:49:44 +0100
commitb42e32047d16cc4389ef63550e525c7b08320172 (patch)
tree3321c5f3bce9fded5c598923f167bc2273535734 /device/peer.go
parentdevice: remove QueueInboundElement leak with stopped peers (diff)
downloadwireguard-go-b42e32047d16cc4389ef63550e525c7b08320172.tar.xz
wireguard-go-b42e32047d16cc4389ef63550e525c7b08320172.zip
device: call wg.Add outside the goroutine
One of the first rules of WaitGroups is that you call wg.Add outside of a goroutine, not inside it. Fix this embarrassing mistake. This prevents an extremely rare race condition (2 per 100,000 runs) which could occur when attempting to start a new peer concurrently with shutting down a device. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
Diffstat (limited to 'device/peer.go')
-rw-r--r--device/peer.go2
1 files changed, 2 insertions, 0 deletions
diff --git a/device/peer.go b/device/peer.go
index 8006b9f..ac85c94 100644
--- a/device/peer.go
+++ b/device/peer.go
@@ -213,6 +213,8 @@ func (peer *Peer) Start() {
// wait for routines to start
+ // RoutineNonce writes to the encryption queue; keep it alive until we are done.
+ device.queue.encryption.wg.Add(1)
go peer.RoutineNonce()
go peer.RoutineSequentialSender()
go peer.RoutineSequentialReceiver()