-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Lint for using await while holding a MutexGuard #4226
Comments
With a recent change to thing.lock().foo().await This kind of lint may become more important for those used to the old behavior. FYI, in Fuchsia, we had 8 instances of this in our codebase at the time of updating to a compiler with the new semantics. 6 of them were caught by compiler errors, but 2 weren't. |
Implementation notes: I think roughly what we want to do here is iterate over all async fns/async blocks in our crate (probably using Ideally this would support mutex implementations other than the standard library (such as So far it's unclear to me whether parking_lot's reentrant locks should be included. |
Other lints about mutexes only lint on std types. I'd suggest to do the same here. |
@flip1995 that makes the lint less useful and catches fewer bugs. Anything named |
Hey I'm interested in taking this on. I will put together a WIP PR based on the guidance above and we can take it from there. |
Fixes rust-lang#4226 This introduces the lint await_holding_lock. For async functions, we iterate over all types in generator_interior_types and look for types named MutexGuard, RwLockReadGuard, or RwLockWriteGuard. If we find one then we emit a lint.
Fixes rust-lang#4226 This introduces the lint await_holding_lock. For async functions, we iterate over all types in generator_interior_types and look for types named MutexGuard, RwLockReadGuard, or RwLockWriteGuard. If we find one then we emit a lint.
@tmandry would it make sense to expand to |
Yeah, probably! Though I'd be inclined to make it a separate lint. (I could be convinced otherwise) |
So the PR is up and there was feedback to match against the full paths of the mutex types. I'm new to this codebase so I'm not sure how to arbitrate that, but I agree wit the above comment that doing so makes this lint much less useful. I made the change to match against full paths to see what it would look like, but I think switching back to just matching against anything named "MutexGuard" is more useful. |
Fixes rust-lang#4226 This introduces the lint await_holding_lock. For async functions, we iterate over all types in generator_interior_types and look for types named MutexGuard, RwLockReadGuard, or RwLockWriteGuard. If we find one then we emit a lint.
Fixes rust-lang#4226 This introduces the lint await_holding_lock. For async functions, we iterate over all types in generator_interior_types and look for types named MutexGuard, RwLockReadGuard, or RwLockWriteGuard. If we find one then we emit a lint.
Fixes rust-lang#4226 This introduces the lint await_holding_lock. For async functions, we iterate over all types in generator_interior_types and look for types named MutexGuard, RwLockReadGuard, or RwLockWriteGuard. If we find one then we emit a lint.
Fixes rust-lang#4226 This introduces the lint await_holding_lock. For async functions, we iterate over all types in generator_interior_types and look for types named MutexGuard, RwLockReadGuard, or RwLockWriteGuard. If we find one then we emit a lint.
Fixes rust-lang#4226 This introduces the lint await_holding_lock. For async functions, we iterate over all types in generator_interior_types and look for types named MutexGuard, RwLockReadGuard, or RwLockWriteGuard. If we find one then we emit a lint.
Fixes rust-lang#4226 This introduces the lint await_holding_lock. For async functions, we iterate over all types in generator_interior_types and look for types named MutexGuard, RwLockReadGuard, or RwLockWriteGuard. If we find one then we emit a lint.
Lint for holding locks across await points Fixes #4226 This introduces the lint await_holding_lock. For async functions, we iterate over all types in generator_interior_types and look for types named MutexGuard, RwLockReadGuard, or RwLockWriteGuard. If we find one then we emit a lint. changelog: introduce the await_holding_lock lint
Lint for holding locks across await points Fixes #4226 This introduces the lint await_holding_lock. For async functions, we iterate over all types in generator_interior_types and look for types named MutexGuard, RwLockReadGuard, or RwLockWriteGuard. If we find one then we emit a lint. changelog: introduce the await_holding_lock lint
Should this lint also be extended to RefCell borrows? It seems they are very similar in this regard. |
Yes, this was brought up earlier. I thought they should probably be separate lints, but don't have a strong opinion here. Please open an issue to discuss further. |
It would be useful to implement a lint against calling
.await
while a holding a MutexGuard.This is almost certainly an error (and a non-obvious one) because the Reactor is going to end up invoking code not visible in the current scope while the lock is held.
The text was updated successfully, but these errors were encountered: