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

Future does not setup waker #1

Open
robo-corg opened this issue Dec 7, 2021 · 2 comments
Open

Future does not setup waker #1

robo-corg opened this issue Dec 7, 2021 · 2 comments

Comments

@robo-corg
Copy link

I am not certain if this is a legitimate problem since I haven't written any breaking tests but looking at the code it seems like it is possible to return a Poll::Pending without registering a waker to fire when the lock was not ready but becomes ready later.

@bddap
Copy link
Contributor

bddap commented Dec 10, 2021

I believe causes a deadlock when multiple futures await an AsyncOnce simultaneously. One of the futures will complete, but the others will not. In the example below, only one test case finishes. The other never finishes.

use std::time::Duration;

use async_once::AsyncOnce;
use lazy_static::lazy_static;

lazy_static! {
    static ref FOO: AsyncOnce<u32> = AsyncOnce::new(async {
        tokio::time::sleep(Duration::from_millis(10)).await;
        1
    });
}

#[tokio::test]
async fn test_one() {
    assert_eq!(FOO.get().await, &1);
}

#[tokio::test]
async fn test_two() {
    assert_eq!(FOO.get().await, &1);
}
> cargo test
running 2 tests
test test_two ... ok
test test_one has been running for over 60 seconds
[dependencies]
async_once = "0.2.1"
lazy_static = "1.4.0"
tokio = { version = "1.14.0", features = ["full"] }

bddap added a commit to bddap/async_once that referenced this issue Dec 10, 2021
bddap added a commit to bddap/async_once that referenced this issue Dec 10, 2021
bddap added a commit to bddap/async_once that referenced this issue Dec 10, 2021
@hjiayz
Copy link
Owner

hjiayz commented Dec 20, 2021

fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants