Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit fixes a deadlock in a unit test which ironically tests for deadlocks. The unit test in question ensures that the `wireguard.Agent` `UpdatePeer` method does not create a deadlock if a concurrent IPCache update is performed. The previous version of this test wanted to ensure this by taking a read-lock on the IPCache, which would ensure that only `UpdatePeer` would make progress (as it also just takes an RLock). However, that approach could lead to a timeout when `ipCache.Upsert` was invoked before `wgAgent.UpdatePeer`, as due to the FIFO nature of underlying mutex implementation, `UpdatePeer` will never obtain an `RLock` if there is a waiting writer. This commit addresses this by taking the `wgAgent` lock instead. This means that `UpdatePeer` will lock the IPCache and then wait for the `wgAgent` lock to become available. Any concurrent IPCache updates will also be blocked until `UpdatePeer` has finished as before. This commit also introduces some additional checks to ensure the spawned go routines have actually been scheduled. This is still best effort, as there is easy way to ensure that a certain method is blocked on a particular mutex. Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
- Loading branch information