mirror of
https://git.zx2c4.com/wireguard-go
synced 2024-11-15 01:05:15 +01: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:
parent
b5f966ac24
commit
b42e32047d
@ -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()
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user