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

types: avoid accessing BoundMutex::inner in derived Debug #225

Merged
merged 1 commit into from
Jun 29, 2024

Conversation

apoelstra
Copy link
Collaborator

We have a submodule bound_mutex whose purpose is to ensure that no deadlocks are possible. We do this by having a short submodule which only accesses the BoundMutex::inner member in the get and set methods. These methods lock the mutex and immediately unlock it. The member is never accessed by any other method. This is easy to check by searching the code for inner.

HOWEVER, there is actually a hidden access to inner in the #[derive(Debug)] line on BoundMutex, and this access is incorrect. Rather than locking the mutex, cloning the Arc within, unlocking, then processing the cloned Arc, it just locks the mutex and then recursively calls stuff while it's locked. Stupid.

Fix this by manually implementing fmt::Debug, calling get rather than directly accessing inner.

Fixes #224.

We have a submodule `bound_mutex` whose purpose is to ensure that no
deadlocks are possible. We do this by having a short submodule which
only accesses the BoundMutex::inner member in the `get` and `set`
methods. These methods lock the mutex and immediately unlock it. The
member is never accessed by any other method. This is easy to check by
searching the code for `inner`.

HOWEVER, there is actually a hidden access to `inner` in the
`#[derive(Debug)]` line on `BoundMutex`, and this access is incorrect.
Rather than locking the mutex, cloning the Arc within, unlocking, then
processing the cloned Arc, it just locks the mutex and then recursively
calls stuff while it's locked. Stupid.

Fix this by manually implementing `fmt::Debug`, calling `get` rather
than directly accessing `inner`.

Fixes #224.
Copy link
Collaborator

@uncomputable uncomputable left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 24fb77a Good catch.

@uncomputable uncomputable merged commit 7af24d4 into master Jun 29, 2024
27 checks passed
@uncomputable uncomputable deleted the 2024-06--deadlock branch June 29, 2024 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deadlock in type inference
2 participants