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

Self wakes are not detected #423

Closed
hds opened this issue May 15, 2023 · 0 comments · Fixed by #430
Closed

Self wakes are not detected #423

hds opened this issue May 15, 2023 · 0 comments · Fixed by #430
Labels
S-bug Severity: bug

Comments

@hds
Copy link
Collaborator

hds commented May 15, 2023

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

No response

What is the issue?

Self wakes are not being detected by tokio console.

How can the bug be reproduced?

The burn task in the app example should result in self wakes, because it calls tokio::task::yield_now() from within the task.

#[tracing::instrument]
async fn burn(min: u64, max: u64) {
    loop {
        for i in min..max {
            for _ in 0..i {
                tokio::task::yield_now().await;
            }
            tokio::time::sleep(Duration::from_secs(i - min)).await;
        }
    }
}

Looking at the logic of yield_now(), it seems that it may not actually result in a self wake (wake being called from within the span of the task being woken). So to check, I replaced the call to yield_now() with a call to a simple_yield_now() which should always wake within the span of the task:

async fn simple_yield_now() {
    pub struct YieldNow {
        yielded: bool,
    }

    impl Future for YieldNow {
        type Output = ();

        fn poll(
            mut self: std::pin::Pin<&mut Self>,
            cx: &mut std::task::Context<'_>,
        ) -> Poll<Self::Output> {
            if self.yielded == true {
                return Poll::Ready(());
            }

            self.yielded = true;
            cx.waker().wake_by_ref();

            Poll::Pending
        }
    }

    YieldNow { yielded: false }.await
}

However, tokio-console still fails to report a self wake.

Logs, error output, etc

We the following in the traces:

2023-05-15T14:07:54.387864Z TRACE runtime.spawn{kind=task task.name=burn task.id=19 loc.file="console-subscriber/examples/self-wake.rs" loc.line=11 loc.col=10}:burn{min=1 max=10}: tokio::task::waker: op="waker.wake_by_ref" task.id=1

Unfortunately, the task.id field in runtime.spawn span refers to the Tokio Task ID of the task, whereas the task.id in the waker event is the Span ID of the runtime.spawn span. So it's not immediately clear why

Versions

  • tokio-console v0.1.8
  • console-subscriber v0.1.9

It's also occuring on main at the time of writing cbf6f5.

Possible solution

No response

Additional context

No response

Would you like to work on fixing this bug?

yes

@hds hds added the S-bug Severity: bug label May 15, 2023
@hawkw hawkw closed this as completed in #430 Jun 1, 2023
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

Successfully merging a pull request may close this issue.

1 participant