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

blocking and block_on tasks have false positive lints #516

Closed
hds opened this issue Feb 7, 2024 · 1 comment
Closed

blocking and block_on tasks have false positive lints #516

hds opened this issue Feb 7, 2024 · 1 comment
Assignees
Labels
A-warnings Area: warnings C-console Crate: console. E-easy Effort: easy. Good for newcomers S-bug Severity: bug

Comments

@hds
Copy link
Collaborator

hds commented Feb 7, 2024

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

tokio-console

What is the issue?

When using the #[tokio::main] macro, some non-async tasks are missed because the console-subscriber is initialized after the runtime has already started. Specifically

  • block_on task
  • blocking tasks for the workers in a multi-thread runtime

This hides a problem which is only visible if the console-susbcriber is started before the runtime. Both these types of tasks trigger false-positive warnings from lints.

How can the bug be reproduced?

The following code reproduces both false positives:

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

    let rt = tokio::runtime::Builder::new_multi_thread()
        .enable_all()
        .build()
        .unwrap();

    rt.block_on(async {
        _ = tokio::spawn(async {
            tokio::time::sleep(std::time::Duration::from_secs(6000)).await;
        })
        .await;
    });
}

Logs, error output, etc

The view in Tokio Console is:

Screenshot 2024-02-07 at 12 33 37

Versions

  • tokio-console 0.1.10 (also on main at the time of reporting)

Possible solution

Only if the kind is task or local should the actual check be performed, if the kind is block_on or blocking then Warning::Ok should be returned.

For the current 3 lints that have been written, block_on and blocking tasks should always return Warning::Ok as the lints only make sense for true async tasks that are polled.

@hds hds added S-bug Severity: bug E-easy Effort: easy. Good for newcomers C-console Crate: console. A-warnings Area: warnings labels Feb 7, 2024
@javihernant
Copy link
Contributor

Hi! I'd like to work on this. It looks like a great issue to get started in tokio-console contributions, which is exactly my idea.

javihernant added a commit to javihernant/console that referenced this issue Feb 7, 2024
change existing lints to only trigger with tasks that are async; those
are all except those with kind 'blocking' and 'block_on'

this commit fixes issue tokio-rs#516
javihernant added a commit to javihernant/console that referenced this issue Feb 7, 2024
change existing lints to only trigger with tasks that are async; those
are all except those with kind 'blocking' and 'block_on'

this commit fixes issue tokio-rs#516
javihernant added a commit to javihernant/console that referenced this issue Feb 7, 2024
change existing lints to only trigger with tasks that are async; those
are all except those with kind 'blocking' and 'block_on'

this commit fixes issue tokio-rs#516
javihernant added a commit to javihernant/console that referenced this issue Feb 8, 2024
change existing lints to only trigger with tasks that are async; those
are all except those with kind 'blocking' and 'block_on'

this commit fixes issue tokio-rs#516
javihernant added a commit to javihernant/console that referenced this issue Feb 8, 2024
change existing lints to only trigger with tasks that are async; those
are all except those with kind 'blocking' and 'block_on'

this commit fixes issue tokio-rs#516
@hawkw hawkw closed this as completed in 4593222 Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-warnings Area: warnings C-console Crate: console. E-easy Effort: easy. Good for newcomers S-bug Severity: bug
Projects
None yet
Development

No branches or pull requests

2 participants