mirror of
https://git.zx2c4.com/wireguard-go
synced 2025-10-10 02:50:08 +08:00
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>
This commit is contained in:

committed by
Jason A. Donenfeld

parent
b5f966ac24
commit
b42e32047d
@@ -352,9 +352,6 @@ func (peer *Peer) RoutineNonce() {
|
||||
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 {
|
||||
|
Reference in New Issue
Block a user