device: handshake routine writes into encryption queue

Since RoutineHandshake calls peer.SendKeepalive(), it potentially is a
writer into the encryption queue, so we need to bump the wg count.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2021-02-09 19:26:45 +01:00
parent 4eab21a7b7
commit da32fe328b
2 changed files with 5 additions and 1 deletions

View File

@ -305,6 +305,7 @@ func NewDevice(tunDevice tun.Device, logger *Logger) *Device {
cpus := runtime.NumCPU()
device.state.stopping.Wait()
device.queue.encryption.wg.Add(cpus) // One for each RoutineHandshake
for i := 0; i < cpus; i++ {
go device.RoutineEncryption()
go device.RoutineDecryption()

View File

@ -237,7 +237,10 @@ func (device *Device) RoutineDecryption() {
/* Handles incoming packets related to handshake
*/
func (device *Device) RoutineHandshake() {
defer device.log.Verbosef("Routine: handshake worker - stopped")
defer func() {
device.log.Verbosef("Routine: handshake worker - stopped")
device.queue.encryption.wg.Done()
}()
device.log.Verbosef("Routine: handshake worker - started")
for elem := range device.queue.handshake.c {