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

Finished tasks sometimes stay in the console and appear busy #189

Closed
daladim opened this issue Dec 2, 2021 · 8 comments
Closed

Finished tasks sometimes stay in the console and appear busy #189

daladim opened this issue Dec 2, 2021 · 8 comments
Labels
C-console Crate: console. S-bug Severity: bug

Comments

@daladim
Copy link
Contributor

daladim commented Dec 2, 2021

Thanks for this great tool, that I'm using to have insights on a large app that spawns many tasks.

When I run the console long enough, it eventually displays busy tasks that run forever.
image

However, I'm quite positive all these tasks are finished. Indeed, these tasks are spawned via

tokio::task::Builder::new().name(some_name).spawn(some_async_function)

and they all have reached the last line of some_async_function, where I added a println!("Finished task {}", some_task_id) that actually got displayed.

So that looks either like a tokio bug that did not joined the task after it reached its last line, or a bug in the console-subscriber that misses some "task is finished" events (or in tokio-console that does not process them).

Ideas to create a minimal reproducer

Have a function that spams tasks, that all complete after some time (let's say after a random (sync or async) sleep between 1 and 40s).
I could try to write it myself if that could be helpful to you.
I am building and running on Win10 if that matters

@zaharidichev
Copy link
Collaborator

I could try to write it myself if that could be helpful to you.

@daladim that would be super useful!

@hawkw
Copy link
Member

hawkw commented Dec 2, 2021

Is it possible that these tasks have completed, but have not yet been dropped? Are the JoinHandles for these tasks stored in a data structure of some kind?

@hawkw hawkw added the C-console Crate: console. label Dec 2, 2021
@colinjfw
Copy link

colinjfw commented Dec 7, 2021

I think I was able to reproduce something similar, if you run the following example for ~2 minutes or so with the latest commit I start to see the idle task count continually increasing.

Theoretically this code should be dropping all of the task handles correctly.

use std::time::Duration;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    console_subscriber::init();
    
    loop {
        let mut tasks = Vec::new();
        for _ in 0..5 {
            let task = tokio::task::spawn(async {
                println!("hello");
            });
            tasks.push(task);
        }
        tokio::time::sleep(Duration::from_millis(100)).await;
        for t in tasks {
            t.await.unwrap();
        }
        println!("awaited");
    }
}

@hawkw
Copy link
Member

hawkw commented Dec 7, 2021

@colinjfw interesting, thanks for the repro!

@daladim
Copy link
Contributor Author

daladim commented Dec 7, 2021

Thanks for doing what I did not have to time do lately :-)
Also, I wasn't totally sure my code did not keep JoinHandles here and there, so that's interesting to see you can reproduce even if your code does drop them

@hawkw
Copy link
Member

hawkw commented Jan 12, 2022

I believe #238 fixes this issue. Are you able to try the latest git revision of console-subscriber (fdc77e2) and confirm that this is the case? You'll also need to build the git version of the console CLI.

@daladim
Copy link
Contributor Author

daladim commented Jan 18, 2022

That's much better now, I no longer see this bug.

Thanks for your work! I'm closing the issue.

@daladim daladim closed this as completed Jan 18, 2022
@hawkw
Copy link
Member

hawkw commented Jan 18, 2022

Great, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-console Crate: console. S-bug Severity: bug
Projects
None yet
Development

No branches or pull requests

5 participants