mirror of
https://github.com/KusakabeShi/EtherGuard-VPN.git
synced 2024-12-27 08:08:46 +01:00
e1fa1cc556
The new test introduced in this commit used to deadlock about 1% of the time. I believe that the deadlock occurs as follows: * The test completes, calling device.Close. * device.Close closes device.signals.stop. * RoutineEncryption stops. * The deferred function in RoutineEncryption drains device.queue.encryption. * RoutineEncryption exits. * A peer's RoutineNonce processes an element queued in peer.queue.nonce. * RoutineNonce puts that element into the outbound and encryption queues. * RoutineSequentialSender reads that elements from the outbound queue. * It waits for that element to get Unlocked by RoutineEncryption. * RoutineEncryption has already exited, so RoutineSequentialSender blocks forever. * device.RemoveAllPeers calls peer.Stop on all peers. * peer.Stop waits for peer.routines.stopping, which blocks forever. Rather than attempt to add even more ordering to the already complex centralized shutdown orchestration, this commit moves towards a data-flow-oriented shutdown. The device.queue.encryption gets closed when there will be no more writes to it. All device.queue.encryption readers always read until the channel is closed and then exit. We thus guarantee that any element that enters the encryption queue also exits it. This removes the need for central control of the lifetime of RoutineEncryption, removes the need to drain the encryption queue on shutdown, and simplifies RoutineEncryption. This commit also fixes a data race. When RoutineSequentialSender drains its queue on shutdown, it needs to lock the elem before operating on it, just as the main body does. The new test in this commit passed 50k iterations with the race detector enabled and 150k iterations with the race detector disabled, with no failures. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com> |
||
---|---|---|
.. | ||
allowedips_rand_test.go | ||
allowedips_test.go | ||
allowedips.go | ||
bind_test.go | ||
constants.go | ||
cookie_test.go | ||
cookie.go | ||
device_test.go | ||
device.go | ||
endpoint_test.go | ||
indextable.go | ||
ip.go | ||
kdf_test.go | ||
keypair.go | ||
logger.go | ||
misc.go | ||
mobilequirks.go | ||
noise_test.go | ||
noise-helpers.go | ||
noise-protocol.go | ||
noise-types.go | ||
peer_test.go | ||
peer.go | ||
pools.go | ||
queueconstants_android.go | ||
queueconstants_default.go | ||
queueconstants_ios.go | ||
receive.go | ||
send.go | ||
sticky_default.go | ||
sticky_linux.go | ||
timers.go | ||
tun_test.go | ||
tun.go | ||
uapi.go | ||
version.go |