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

Autodetection of new execution not always working #518

Open
javihernant opened this issue Feb 10, 2024 · 0 comments
Open

Autodetection of new execution not always working #518

javihernant opened this issue Feb 10, 2024 · 0 comments
Labels
S-bug Severity: bug

Comments

@javihernant
Copy link
Contributor

javihernant commented Feb 10, 2024

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

@javihernant javihernant added the S-bug Severity: bug label Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-bug Severity: bug
Projects
None yet
Development

No branches or pull requests

1 participant