Skip to content

Autodetection of new execution not always working #518

@javihernant

Description

@javihernant

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

Tokio-console and console-subscriber

What is the issue?

tokio-console has a mechanism to restart itself if it detects a new program has attached. For example: I'm running a.rs, and after that I decide to stop the process and run b.rs. Console will detect b.rs is a different process and will update the list of tasks to only show those of b.rs. However, not always does this detection work.

If a.rs and b.rs are using the #[tokio::main] macro to initialize the runtime, then detection works fine. However, if one is using #[tokio::main] macro, whereas the other is using tokio::runtime::Runtime::new() this detection does not take place. The result is tasks from a.rs gets mixed in with the ones from b.rs

How can the bug be reproduced?

As I described before, it can be reproduced with one program using the #[tokio::main] and the other using tokio::runtime::Runtime::new().

Steps:

  1. run a.rs
  2. run tokio-console
  3. stop a.rs
  4. run b.rs
  5. view console showing tasks from a.rs and b.rs

Program using #[tokio::main] macro (a.rs)

use std::time::Duration;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    console_subscriber::init();
    let seconds = 6000;
    let task = tokio::task::Builder::new()
        .name("task1")
        .spawn(wait(6000))
        .unwrap();
    let result = tokio::try_join! {
        task,
    };
    result?;

    Ok(())
}

async fn wait(seconds: u64) {
    tokio::time::sleep(Duration::from_secs(seconds)).await;
}

Program using tokio::runtime::Runtime::new() (b.rs)

use std::time::Duration;

fn main() {
    console_subscriber::init();

    let rt = tokio::runtime::Runtime::new()
        .unwrap();
    rt.block_on(async {
            tokio::time::sleep(std::time::Duration::from_secs(6000)).await;
        });
}

Logs, error output, etc

No response

Versions

console-api v0.6.0
console-subscriber v0.2.0

Possible solution

I don't know

Additional context

Screenshot from 2024-02-09 19-16-48

Would you like to work on fixing this bug?

yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    S-bugSeverity: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions