]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
Give bind its own wait group
authorJason A. Donenfeld <Jason@zx2c4.com>
Sun, 20 May 2018 04:19:29 +0000 (06:19 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Sun, 20 May 2018 04:29:21 +0000 (06:29 +0200)
In a waitgroup, all waits must come after all adds

conn.go
device.go
receive.go

diff --git a/conn.go b/conn.go
index b79b9cd6ecdcfb2062d569ac0e729ea9b78a37e8..ded74194d6d38264785f577861d331fd3989c0f3 100644 (file)
--- a/conn.go
+++ b/conn.go
@@ -75,6 +75,7 @@ func unsafeCloseBind(device *Device) error {
                err = netc.bind.Close()
                netc.bind = nil
        }
+       netc.stopping.Wait()
        return err
 }
 
@@ -162,10 +163,11 @@ func (device *Device) BindUpdate() error {
 
                // start receiving routines
 
-               device.state.starting.Add(ConnRoutineNumber)
-               device.state.stopping.Add(ConnRoutineNumber)
+               device.net.starting.Add(ConnRoutineNumber)
+               device.net.stopping.Add(ConnRoutineNumber)
                go device.RoutineReceiveIncoming(ipv4.Version, netc.bind)
                go device.RoutineReceiveIncoming(ipv6.Version, netc.bind)
+               device.net.starting.Wait()
 
                device.log.Debug.Println("UDP bind has been updated")
        }
index 6758cbc73b2afb27549b446e9796b609766bba40..7a23350ae695c8638d87d381ff7a2e7b2435433a 100644 (file)
--- a/device.go
+++ b/device.go
@@ -35,6 +35,8 @@ type Device struct {
        }
 
        net struct {
+               starting sync.WaitGroup
+               stopping sync.WaitGroup
                mutex  sync.RWMutex
                bind   Bind   // bind interface
                port   uint16 // listening port
index 0f8554f6341c13cf6f668bba7e37003de087354d..29fe5e98e40868b5e9c5b5cc29f44ead3bab9f93 100644 (file)
@@ -125,11 +125,11 @@ func (device *Device) RoutineReceiveIncoming(IP int, bind Bind) {
        logDebug := device.log.Debug
        defer func() {
                logDebug.Println("Routine: receive incoming IPv" + strconv.Itoa(IP) + " - stopped")
-               device.state.stopping.Done()
+               device.net.stopping.Done()
        }()
 
        logDebug.Println("Routine: receive incoming IPv" + strconv.Itoa(IP) + " - starting")
-       device.state.starting.Done()
+       device.net.starting.Done()
 
        // receive datagrams until conn is closed