-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add lint for holding a tracing
Span Guard Across an .await
#8434
Add lint for holding a tracing
Span Guard Across an .await
#8434
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @camsteffen (or someone else) soon. Please see the contribution instructions for more information. |
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.
This adds another dependency to an external crate. Clippy is not a tool to implement crate-specific lints. We have exceptions for regex
, serde
and parking_lot
.
- regex is a repo of the rust-lang org
- serde is IMHO a relic of the past, for which I don't see the justification for the 2 lints we have for it.
- parking_lot was added, because many people use those mutexes over the
std
mutexes in production code and there is the possibility thatparking_lot
will replace thestd
implementation at some point.
So I'm not sure if we should continue sliding down this slope of adding more and more lints for external/non-std crates.
Also those two points by you rather convince me to not add it to Clippy:
- However, instead of that causing a deadlock, incorrect traces will be reported.
So it doesn't break you program, if you do this. You just see weird output, right? You can also google why that happens I assume. It's also in the documentation. I made this point before, but it is not Clippy's resposibility to point people to documentation or explicitly spell out the documentation for them
- I expect that tracing will move to it as soon as its MSRV allows it to. Once that occurs, I would be in favor of removing this lint from clippy.
Adding a lint to Clippy with a deadline in mind when it can be removed is questionable. Instead of adding the lint, wouldn't it make more sense to put that work into the feature so it get's stabilized quicker?
I'll nominate this PR for discussion in our next Clippy meeting.
Thanks for leaving your thoughts! As for:
No worries, I think that this is should be ironed out. I know the feeling of being responsible for crates/code that you'd rather not be and finding a clear policy is tricky, and if this PR is rejected but a clear policy comes of it, then I'd consider that this PR to be a net benefit.
Possibly, but the work needed to land |
Given that this may (probably) be fixed by |
☔ The latest upstream changes (presumably #8419) made this pull request unmergeable. Please resolve the merge conflicts. |
No worries! Then it might be better to see what can be done to improve |
Add `await_holding_invalid_type` lint changelog: [`await_holding_invalid_type`] This lint allows users to create a denylist of types which are not allowed to be held across await points. This is essentially a re-implementation of the language-level [`must_not_suspend` lint](rust-lang/rust#83310). That lint has a lot of work still to be done before it will reach Rust stable, and in the meantime there are a lot of types which can trip up developers if they are used improperly. I originally implemented this specifically for `tracing::span::Entered`, until I discovered #8434 and read the commentary on that PR. Given this implementation is fully user configurable, doesn't tie clippy to any one particular crate, and introduces no additional dependencies, it seems more appropriate.
Hello! This PR adds a new pedantic lint,
[`await_holding_span_guard`]
that prohibits the usage of a tracing span guard across an await boundary. If atracing
Span guard is used across an await boundary, tracing will record incorrect traces that don't appear until concurrent execution of futures occurs. In practice, this means that this issue won't occur while testing locally. While this is mentioned in tracing's documentation, I believe that this is a footgun that is best addressed through a lint or some language changes. Until such a feature can be landed, I think that a Clippy lint is the most expedient approach.As for whether this lint should be included within Clippy, I think it should, but I can see the arguments why it shouldn't. In any case, here are the reasons in favor of inclusion within Clippy:
tracing
is probably the smallest of those three crates, it does have some non-trivial usage across the ecosystem (e.g., Tokio, rustc, chalk). Unfortunately, I don't have a principled policy in mind for what crates can and cannot be linted by Clippy and I understand if linting tracing is a step too far.Some additional notes for review:
#[must_not_suspend]
lands in rustc, I expect that tracing will move to it as soon as its MSRV allows it to. Once that occurs, I would be in favor of removing this lint from clippy.#[must_not_suspend]
, should this lint be renamed to#[`suspend_holding_span_guard`]
? Should this lint havetracing
in the name?changelog: Add a lint for holding a
tracing
Span guard across an.await
boundary.