Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wireguard: Fix timeout in unit test #16001

Merged
merged 1 commit into from
May 6, 2021

Commits on May 5, 2021

  1. wireguard: Fix timeout in unit test

    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>
    gandro committed May 5, 2021
    Configuration menu
    Copy the full SHA
    fc3a3a0 View commit details
    Browse the repository at this point in the history