awslabs / awslabs/shuttle

Tokio::sync::Notify::notify_one is wrong (should be fair)

Open
#288 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1.1k
Forks
59
Avg merge
4d 2h
Merged PRs (30d)
15

Description

Per the tokio docs:
```
Notifies the first waiting task.

If a task is currently waiting, that task is notified. Otherwise, a permit is stored in this Notify value and the next call to [notified().await](https://docs.rs/tokio/latest/tokio/sync/struct.Notify.html#method.notified) will complete immediately consuming the permit made available by this call to notify_one().

At most one permit may be stored by Notify. Many sequential calls to notify_one will result in a single permit being stored. The next call to notified().await will complete immediately, but the one after that will wait.
```

We do the following currently:
```rust
// Choose a pending waiter at random
let index = state.rng.gen_range(0..pending.len());
```

Which is not the first waiting task.

Looking at `Notify` it seems like the whole module is due for a revisit

Contributor guide

Open the contributing guide

Research direction

Start by reading the Tokio Notify documentation and the Notify implementation around the random pending-waiter selection shown in the issue. Compare the implementation with the documented waiting order; done means notify_one selects the first waiting task rather than a random pending waiter, while the broader Notify-module revisit may need separate scope.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.