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.go | ||
allowedips_rand_test.go | ||
allowedips_test.go | ||
bind_test.go | ||
constants.go | ||
cookie.go | ||
cookie_test.go | ||
device.go | ||
device_test.go | ||
endpoint_test.go | ||
indextable.go | ||
ip.go | ||
kdf_test.go | ||
keypair.go | ||
logger.go | ||
misc.go | ||
mobilequirks.go | ||
noise-helpers.go | ||
noise-protocol.go | ||
noise-types.go | ||
noise_test.go | ||
peer.go | ||
peer_test.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.go | ||
tun_test.go | ||
uapi.go | ||
version.go |