Skip to content

extra::sync has racy functions #7522

Description

@mstewartgallus

Consider the following function in extra::sync. There is a race condition where after the peek another thread can recv from the head port. This race condition looks like it would cause an accident an extremely small number of times because the peek, and the recv are so close together but when the action does occur it will cause the really bad, and unexpected (to the user of Waitqueue) effect of the signal method to block on head!

fn signal_waitqueue(q: &Waitqueue) -> bool {
    // The peek is mandatory to make sure recv doesn't block.
    if q.head.peek() {
        // Pop and send a wakeup signal. If the waiter was killed, its port
        // will have closed. Keep trying until we get a live task.
        if comm::try_send_one(q.head.recv(), ()) {
            true
        } else {
            signal_waitqueue(q)
        }
    } else {
        false
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions