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

Fix code that could lead to a possible deadlock. #1380

Merged
merged 6 commits into from
Mar 20, 2022
Merged

Fix code that could lead to a possible deadlock. #1380

merged 6 commits into from
Mar 20, 2022

Commits on Mar 19, 2022

  1. Fix code that could lead to a possible deadlock.

    Drop implementations are not called until the end of a statement. The statement changed in this commit therefore took 4 read locks on a RwLock which can lead to problems if a write lock is requested between any of these read locks. The code looks like it would only hold one lock at a time but it does not drop any of the locks until after the arithmatic operations complete, which leads to this situation. See https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=996079046184329f3a9df1cd19c87da8 to see this in action. The fix is to just take one lock and share it between the three calls to num_presses, letting it drop at the end of the scope.
    DusterTheFirst committed Mar 19, 2022
    Configuration menu
    Copy the full SHA
    9673b8f View commit details
    Browse the repository at this point in the history
  2. Fix code that may cause a deadlock in MenuRoot::stationary_interaction

    The issue here is related to that in 9673b8f in that the lock is not dropped when it is expected.  Since the `RwLockReadGuard` produced by `ctx.input()` has a reference taken from it (one into `pointer`), the lock cannot be dropped until that reference is no longre valid, which is the end of the scope (in this case this function).  The following `ctx.input()` then attempts to aquire a second lock on the `RwLock`, creating the same situation that was found in the referenced commit.
    
    This has been resolved by holding one lock on the input for the whole function.
    DusterTheFirst committed Mar 19, 2022
    Configuration menu
    Copy the full SHA
    5ef68ac View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    11ed9f2 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    7a0ccfd View commit details
    Browse the repository at this point in the history

Commits on Mar 20, 2022

  1. Use full link to PR

    emilk authored Mar 20, 2022
    Configuration menu
    Copy the full SHA
    7d393c1 View commit details
    Browse the repository at this point in the history
  2. Use full link to PR

    emilk authored Mar 20, 2022
    Configuration menu
    Copy the full SHA
    7e820d9 View commit details
    Browse the repository at this point in the history