-
-
Notifications
You must be signed in to change notification settings - Fork 142
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
Console doesn't detect self wakes from tokio::task::yield_now()
after Tokio 1.23
#512
Comments
Edit: oh haha i can't read, i missed the first paragraph that references tokio-rs/tokio#5223 As a side note, it would be really cool if we had some way to run automated tests against new |
Thinking about this...I honestly think it might be okay to just exclude The primary reason we want to warn about tasks self-waking is that excessive self-wakes can result in a task starving the runtime by waking itself, getting put in the LIFO slot, and immediately executing again. Since tokio-rs/tokio#5223 changes @hds what do you think? |
@hawkw that's a good point regarding In that case it's more a question of changing the tests and documenting the limitation in self wake counting. I'll do that and then we can probably close this issue. Thanks! |
Sounds good to me, thanks for flagging this! |
I missed this first comment yesterday. This is a good idea, although I think we might want to test against tokio In a certain way this might be easier than the webhook - although having that webhook to catch things on the actual release would also be really nice. |
tokio::task::yield_now()
after Tokio 1.23
Part of the testing performed in the `console-subscriber` integration tests is detecting self wakes. This relied upon the `yield_now()` from Tokio. However, the behavior of this function was changed in tokio-rs/tokio#5223 and since Tokio 1.23 the wake doesn't occur in the task that `yield_now()` is called from. This breaks the test when using a newer version of Tokio. This change replaces the use of `yield_now()` with a custom `self_wake()` function that returns a future which does perform a self wake (wakes the task from within itself before returning `Poll::Pending`). The same custom `self_wake()` is also included in the `app` example so that it shows self wakes correctly. Tokio has been updated to 1.28.2 in the lock file (the last with compatible MSRV) so that this fix is tested. Ref #512
Part of the testing performed in the `console-subscriber` integration tests is detecting self wakes. This relied upon the `yield_now()` from Tokio. However, the behavior of this function was changed in tokio-rs/tokio#5223 and since Tokio 1.23 the wake doesn't occur in the task that `yield_now()` is called from. This breaks the test when using a newer version of Tokio. This change replaces the use of `yield_now()` with a custom `self_wake()` function that returns a future which does perform a self wake (wakes the task from within itself before returning `Poll::Pending`). The same custom `self_wake()` is also included in the `app` example so that it shows self wakes correctly. Tokio has been updated to 1.28.2 in the lock file (the last with compatible MSRV) so that this fix is tested. Ref #512
(edit(2024-01-24): Updated title and description to clarfiy that it is only self wakes coming from
tokio::task::yield_now()
that are affected)What is the issue?
When observing an instrumented program built with Tokio 1.23 or later, Tokio Console isn't able to detect self wakes coming from
tokio::task::yield_now()
.This is due to tokio-rs/tokio#5223, where the self wake was changed to be deferred so that self waking tasks wouldn't starve the resource drivers.
How can the bug be reproduced?
The following code should show a task with a single self wake:
If build with Tokio 1.22.0 then we see the wake counted as a self wake in Tokio Console. We can confirm this using
ari-subscriber
where we get the output (truncated):Specifically there is a wake operation (
op="waker.wake_by_ref"
) inside theruntime.spawn
span.When updating to Tokio 1.23.0, Tokio Console no longer counts the single wake as a self wake. Again, we can confirm using
ari-subscriber
(truncated output):Here we see that the waker is cloned (
op="waker.clone"
) within theruntime.spanw
span for the task, but the wake itself happens by value after the span has exited (op="waker.wake"
).Logs, error output, etc
No response
Versions
Tokio 1.23
Possible solution
We may need to modify the instrumentation in Tokio itself to be able to detect a self wake. Since Tokio knows that it is performing a self wake (the deferred waking code is only used from
tokio::task::yield_now()
), it may be possible to explicitly include in the instrumentation when a wake is a self wake.It's not necessarily straight forward though, this code passes through the std library
Waker
object.Additional context
No response
Would you like to work on fixing this bug?
yes
The text was updated successfully, but these errors were encountered: