Skip to content

Commit

Permalink
fix(console): only trigger lints on async tasks (#517)
Browse files Browse the repository at this point in the history
This branch changes existing lints to only trigger with tasks that are
async; those are all except those with kind 'blocking' and 'block_on'.

Fixes #516
  • Loading branch information
javihernant authored Feb 8, 2024
1 parent bd3dd71 commit 4593222
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tokio-console/src/state/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ impl Task {
self.stats.last_wake > self.stats.last_poll_started
}

pub(crate) fn is_blocking(&self) -> bool {
matches!(self.kind.as_ref(), "block_on" | "blocking")
}

pub(crate) fn is_completed(&self) -> bool {
self.stats.total.is_some()
}
Expand Down
12 changes: 12 additions & 0 deletions tokio-console/src/warnings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ impl Warn<Task> for SelfWakePercent {
}

fn check(&self, task: &Task) -> Warning {
// Don't fire warning for tasks that are not async
if task.is_blocking() {
return Warning::Ok;
}
let self_wakes = task.self_wake_percent();
if self_wakes > self.min_percent {
Warning::Warn
Expand All @@ -174,6 +178,10 @@ impl Warn<Task> for LostWaker {
}

fn check(&self, task: &Task) -> Warning {
// Don't fire warning for tasks that are not async
if task.is_blocking() {
return Warning::Ok;
}
if !task.is_completed()
&& task.waker_count() == 0
&& !task.is_running()
Expand Down Expand Up @@ -222,6 +230,10 @@ impl Warn<Task> for NeverYielded {
}

fn check(&self, task: &Task) -> Warning {
// Don't fire warning for tasks that are not async
if task.is_blocking() {
return Warning::Ok;
}
// Don't fire warning for tasks that are waiting to run
if task.state() != TaskState::Running {
return Warning::Ok;
Expand Down

0 comments on commit 4593222

Please sign in to comment.