From 45932229fb5aea7a4994a7644bded9baf2776ea8 Mon Sep 17 00:00:00 2001 From: mersey <73640929+javihernant@users.noreply.github.com> Date: Thu, 8 Feb 2024 18:49:29 +0100 Subject: [PATCH] fix(console): only trigger lints on async tasks (#517) 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 --- tokio-console/src/state/tasks.rs | 4 ++++ tokio-console/src/warnings.rs | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/tokio-console/src/state/tasks.rs b/tokio-console/src/state/tasks.rs index d39278664..59b966a5b 100644 --- a/tokio-console/src/state/tasks.rs +++ b/tokio-console/src/state/tasks.rs @@ -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() } diff --git a/tokio-console/src/warnings.rs b/tokio-console/src/warnings.rs index 59d43f99f..b7d6ec44e 100644 --- a/tokio-console/src/warnings.rs +++ b/tokio-console/src/warnings.rs @@ -148,6 +148,10 @@ impl Warn 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 @@ -174,6 +178,10 @@ impl Warn 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() @@ -222,6 +230,10 @@ impl Warn 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;