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

Hang with LocalSet #3117

Closed
alecmocatta opened this issue Nov 10, 2020 · 3 comments · Fixed by #3369
Closed

Hang with LocalSet #3117

alecmocatta opened this issue Nov 10, 2020 · 3 comments · Fixed by #3369
Assignees
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. E-help-wanted Call for participation: Help is requested to fix this issue. M-task Module: tokio/task

Comments

@alecmocatta
Copy link

Version

0.3.3 (current latest)

Platform

Tested on Linux and macOS

Description

This code hangs, whereas I would expect it to complete. The LocalSet is being awaited upon, therefore I would expect the spawned task to complete.

use futures::{
    future::{pending, ready},
    FutureExt,
};
use tokio::task::LocalSet;

#[tokio::main]
async fn main() {
    let ls = LocalSet::new();
    futures::select! {
        _ = ls.run_until(pending::<()>()).fuse() => unreachable!(),
        ret = async { ls.spawn_local(ready(())).await.unwrap() }.fuse() => ret
    }
}

(Playground)

@alecmocatta alecmocatta added A-tokio Area: The main tokio crate C-bug Category: This is a bug. labels Nov 10, 2020
@Darksonn Darksonn added the M-task Module: tokio/task label Nov 11, 2020
@Darksonn
Copy link
Contributor

I played a bit around with this. The cause appears to be the following:

  1. The select! polls the first branch, resulting in a run_until call that's sleeping.
  2. The select! polls the second branch, spawning the future onto the local set.
  3. But run_until is sleeping and the spawn does not emit a wake-up to it, so it keeps sleeping.

If you change it to spawn first, or for run_until to have a wake-up after the spawn, then it works.

@carllerche
Copy link
Member

Seems like a spawn should result in waking the local set?. cc @hawkw

@hawkw
Copy link
Member

hawkw commented Nov 12, 2020

Seems like a spawn should result in waking the local set?. cc @hawkw

That seems right, we can do that!

@carllerche carllerche added the E-help-wanted Call for participation: Help is requested to fix this issue. label Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. E-help-wanted Call for participation: Help is requested to fix this issue. M-task Module: tokio/task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants