-
Notifications
You must be signed in to change notification settings - Fork 1.6k
False-positive await_holding_lock
with manual drop
of MutexGuard
#9683
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
Comments
I'm not sure if this use case is common enough to make the lint handle it. I would throw an |
I’m doing that, and it is a good workaround for me. I still think its a valid false-positive, even if the solution right now is "not worth the effort fixing". |
Wanted to add that this was affecting me also today, perhaps this is more common than suggested by kraktus. (we ran into it in a resource management loop, which is for us at least a somewhat common pattern) |
I also came across this for a loop. The lock is needed at the start and end of the loop. By dropping the lock manually, the mutex only needs to be locked once per iteration instead of twice. let mut lock = mutex.lock().unwrap();
loop {
let future = start_computation(&lock);
drop(lock);
let result = future.await;
lock = mutex.lock().unwrap();
apply_result(&lock, result);
} |
duplicate of #6446? |
Summary
I manually
drop
myMutexGuard
right before theawait
point, therefore the lock is not held across await points.Lint Name
await_holding_lock
Reproducer
I tried this code:
I saw this happen:
I expected to see this happen:
This should not error as the
MutexGuard
is not alive at theawait
point.Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: