Skip to content
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

Ensure all locks (.lock(), .read(), .write(), etc.) aren't held over if let statements #24836

Closed
buffalu opened this issue Apr 29, 2022 · 8 comments
Labels
stale [bot only] Added to stale content; results in auto-close after a week.

Comments

@buffalu
Copy link
Contributor

buffalu commented Apr 29, 2022

Problem

See this for context:
rust-lang/rust#93883
https://www.reddit.com/r/rust/comments/ldic3m/confusing_point_regarding_scope_and_dropped_value/

I was recently running into some type of deadlock issue in block_subscribe which i narrowed down to unexpectedly holding locks across if let. Something like:

if let Some(bank) = bank_forks.read().unwrap().get(slot) {}

Proposed Solution

@jstarry
Copy link
Member

jstarry commented Apr 29, 2022

Once this clippy lint makes it into nightly, I think we should start applying it in CI: rust-lang/rust#93883

@jstarry
Copy link
Member

jstarry commented May 9, 2022

The latest nightly rust (rust version 1.62.0-nightly (cb1219871 2022-05-08)) now has the lint I linked above and it can be run with cargo +nightly clippy -- -W clippy::significant_drop_in_scrutinee

@brooksprumo
Copy link
Contributor

brooksprumo commented May 9, 2022

Clippy found these two:

warning: temporary with significant drop in match scrutinee
    --> runtime/src/bank.rs:2935:36
     |
2935 |             let vote_state = match vote_account.vote_state().deref() {
     |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: requested on the command line with `-W clippy::significant-drop-in-scrutinee`
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#significant_drop_in_scrutinee

(PR #25094 to fix the above warning.)

warning: temporary with significant drop in match scrutinee
   --> gossip/src/cluster_info.rs:863:76
    |
863 |                     let epoch_slots = gossip_crds.get::<&CrdsValue>(&label)?.epoch_slots()?;
    |                                                                            ^
    |
    = note: requested on the command line with `-W clippy::significant-drop-in-scrutinee`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#significant_drop_in_scrutinee

@jstarry
Copy link
Member

jstarry commented May 9, 2022

Hmm can you try running before the recent patches on master? I would have expected a few more

@brooksprumo brooksprumo changed the title Ensure all locks (.lock(), .read(), .write(), etc.) aren't help over if let statements Ensure all locks (.lock(), .read(), .write(), etc.) aren't held over if let statements May 9, 2022
@brooksprumo
Copy link
Contributor

Hmm can you try running before the recent patches on master? I would have expected a few more

I ran it again from commit 9a136aa684—which is the one before a61652104b "Avoid holding lock guards in match expressions (#24805)"—and got the same results (even after an explicit cargo +nightly clean too)... So that's strange...

Was there a different commit you wanted me to run against? It may be worthwhile to double check my results by running it also, so there's another datapoint. Maybe this new lint doesn't pick up everything yet?

@jstarry
Copy link
Member

jstarry commented May 10, 2022

Hmm I'm thinking it's not working quite right yet then. Would be interesting to dig into why. (cc @PrestonFrom if you want to join in)

@PrestonFrom
Copy link

PrestonFrom commented May 11, 2022

@jstarry Thanks for letting me know. I think I found the issue -- working on a fix but not sure on the timeline.

@jstarry
Copy link
Member

jstarry commented May 11, 2022

@jstarry Thanks for letting me know. I think I found the issue -- working on a fix but not sure on the timeline.

Happy to hear that, thanks for taking a look. No rush from us, we really appreciate your work so far on that lint!

@github-actions github-actions bot added the stale [bot only] Added to stale content; results in auto-close after a week. label May 12, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale [bot only] Added to stale content; results in auto-close after a week.
Projects
None yet
Development

No branches or pull requests

5 participants
@brooksprumo @jstarry @PrestonFrom @buffalu and others