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>
// 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()
device := peer.device
logDebug := device.log.Debug
- // We write to the encryption queue; keep it alive until we are done.
- device.queue.encryption.wg.Add(1)
-
flush := func() {
for {
select {