console icon indicating copy to clipboard operation
console copied to clipboard

Lost waker false positive when task has detatched

Open davidlattimore opened this issue 2 years ago • 0 comments

What crate(s) in this repo are involved in the problem?

tokio-console, console-subscriber

What is the issue?

I see there have been false positives in the past, but since #149 is resolved, I'll file a fresh issue for this specific case.

I'm seeing tokio-console reporting that tasks have lost their waker, when in fact the task has finished.

This seems to happen if the task in question spawned another task, but then dropped the join handle for the subtask. The parent task then only shows as complete once the subtask finishes.

How can the bug be reproduced?

The following code is able to reproduce the problem. The warning shows for 10 seconds, then goes away for the next 10 seconds before the program terminates.

use anyhow::Result;
use futures_channel::oneshot;
use std::time::Duration;

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
    console_subscriber::init();

    let (send, recv) = oneshot::channel::<()>();

    const DELAY: Duration = Duration::from_secs(10);

    tokio::task::spawn(async move {
        tokio::time::sleep(DELAY).await;
        drop(send);
    });

    // The following task (outer task) finishes almost instantly (the println
    // below is reached). However tokio-console says that it has lost its waker
    // and will never be woken. Only once the inner task finishes is the outer
    // task marked as terminated.
    tokio::task::spawn(async move {
        tokio::task::spawn(async move {
            let _ = recv.await;
        });
    })
    .await
    .unwrap();

    println!("Waiting to finish");

    tokio::time::sleep(DELAY * 2).await;
    Ok(())
}
[package]
name = "t1"
version = "0.1.0"
edition = "2021"

[dependencies]
tokio = { version = "1.20.1" }
console-subscriber = "0.1.8"
anyhow = "1.0.65"
futures-channel = "0.3.24"

Logs, error output, etc

No response

Versions

$
cargo tree | grep console-
├── console-subscriber v0.1.8
│   ├── console-api v0.4.0

$ tokio-console -V
tokio-console 0.1.7

Possible solution

No response

Additional context

No response

Would you like to work on fixing this bug?

maybe

davidlattimore avatar Sep 25 '22 11:09 davidlattimore