-
Notifications
You must be signed in to change notification settings - Fork 624
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
Fix incorrect usage of tracing span in async functions. #10663
Conversation
@nagisa Any idea how to make this lintable? It's pretty subtle and I don't imagine this is very common knowledge. On the other hand, it's not such a huge deal because we don't use a lot async functions outside of networking code. Still, one day someone is going to do this again. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #10663 +/- ##
==========================================
+ Coverage 71.67% 71.71% +0.03%
==========================================
Files 756 756
Lines 152394 152413 +19
Branches 152394 152413 +19
==========================================
+ Hits 109231 109300 +69
+ Misses 38184 38156 -28
+ Partials 4979 4957 -22
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
I wonder if it is possible to check statically if you are inside an async function. If it possible to do that, then we could introduce that check around the call to span. Would something like that work? |
I don't think there are easy ways to prevent One way would be to have More reasonably, this wouldn't have occurred if we chosen to use the I would suggest doing exactly that in this instance instead of manually unrolling
The warning to that effect is alluded to within the first page of the All that said this is my first time seeing this sort of misuse becoming a stack overflow. I would consider sending a bug report to the upstream project(s) with a minimal reproducer they could experiment with. If you have the time for it, of course. |
.instrument(tracing::trace_span!( | ||
target: "network", | ||
"receive_routed_message", | ||
"type" = body_type, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case #[instrument]
application would need to use an initially empty field and then record it later as demonstrated in the last example here.
As for diagnostics: rust-lang/rust#83310 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving to unblock.
I'm merging this to unblock the stack overflow issue, but not improving upon it as I don't have the bandwidth right now. Thanks @nagisa for your thoughts! |
Pushing people towards the `tracing::*_span!` has caused us some significant grief, especially in near#10663 so we better allow and encourage `#[instrument]`.
Pushing people towards the `tracing::*_span!` has caused us some significant grief, especially in #10663 so we better allow and encourage `#[instrument]`.
See https://docs.rs/tracing/latest/tracing/struct.Span.html#method.enter
It is incorrect to do this:
because when the function yields, the tracing span remains entered. This causes incorrect span nesting, and we have observed a stack overflow as a result, when the system is under load.