Skip to content

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented Dec 31, 2022

Both double_lock_detected() and potential_deadlock_detected() functions call LogPrintf() which in turn implies locking of the Logger::m_cs mutex. To avoid a deadlock, the latter must not have the Mutex type (see #16112).

With this PR the mentioned restriction has been lifted, and it is possible now to use our regular Mutex type for the Logger::m_cs mutex instead of a dedicated StdMutex type (not introducing that change here, as its diff is much bigger than a few lines, and the currently proposed diff seems valuable by itself).

Note for reviewers: Make sure the code is configured and built with CPPFLAGS=-DDEBUG_LOCKORDER.

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 31, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/26781.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK vasild, ryanofsky

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

No conflicts as of last run.

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

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

ACK 20647b8

@achow101 achow101 requested a review from ryanofsky April 25, 2023 15:49
@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 8, 2023

There hasn't been much activity lately. What is the status here?

Finding reviewers may take time. However, if the patch is no longer relevant, please close this pull request. If the author lost interest or time to work on this, please close it and mark it 'Up for grabs' with the label, so that it can be picked up in the future.

@hebasto
Copy link
Member Author

hebasto commented Aug 8, 2023

cc @ryanofsky

Both `double_lock_detected()` and `potential_deadlock_detected()`
functions call `LogPrintf()` which in turn implies locking of the
`Logger::m_cs` mutex. To avoid a deadlock the latter must not have the
`Mutex` type.
With this change the mentioned restriction has been lifted, and it is
possible now to use our regular `Mutex` type for the `Logger::m_cs`
mutex instead of a dedicated `StdMutex` type.
@hebasto
Copy link
Member Author

hebasto commented Feb 12, 2024

Rebased to refresh the CI.

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

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

ACK 38f93fe

@hebasto
Copy link
Member Author

hebasto commented Mar 8, 2024

@maflcko @ryanofsky

Do you mind having a look into this PR please?

@maflcko
Copy link
Member

maflcko commented Mar 11, 2024

Sure, seems fine, but I don't see the benefit, if the logger is kept as-is?

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Code review ACK 38f93fe. This seems like a good change, but I think it would be better if it had another commit getting rid of StdMutex/StdLockGuard. Otherwise nothing is really taking advantage of the change.

@@ -172,6 +172,7 @@ static void push_lock(MutexType* c, const CLockLocation& locklocation)
// same thread as that results in an undefined behavior.
auto lock_stack_copy = lock_stack;
lock_stack.pop_back();
lock.unlock();
Copy link
Contributor

Choose a reason for hiding this comment

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

In commit "Release LockData::dd_mutex before calling *_detected functions" (08cfe27)

Would be good to have a comment saying why this is necessary. If I understand correctly it could say something like // Release dd_mutex before calling double_lock_detected to avoid deadlocks, so no other lock is ever acquired after dd_mutex, and lock order is consistent.

@@ -182,9 +183,11 @@ static void push_lock(MutexType* c, const CLockLocation& locklocation)

const LockPair p2 = std::make_pair(c, i.first);
if (lockdata.lockorders.count(p2)) {
auto lock_stack_copy = lock_stack;
auto lock_stack_current = lock_stack;
Copy link
Contributor

Choose a reason for hiding this comment

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

In commit "Release LockData::dd_mutex before calling *_detected functions" (08cfe27)

Previous name lock_stack_copy seems like it explains the purpose for this variable better than lock_stack_current. Also lock_stack_copy is the name used above and it would be nicer if double_lock_detected and potential_deadlock_detected cases were handled consistently I think, unless I am missing something.

@achow101
Copy link
Member

@hebasto Are you planning on addressing review feedback here?


I think it would be better if it had another commit getting rid of StdMutex/StdLockGuard. Otherwise nothing is really taking advantage of the change.

I agree. The PR description sounded like this was going to be the ultimate change, but it does not appear to have actually been done.

@vasild
Copy link
Contributor

vasild commented Jun 21, 2024

I re-reviewed this again and retain my ACK because IMO it is an improvement to master even without further changes because it reduces the scope where the mutex is held. I don't see the fact that it can go further as a blocker for this.

I would be happy to review changing StdMutex m_cs to Mutex m_cs here or in another PR.

The PR description sounded like this was going to be the ultimate change

well, fwiw, the description contains "not introducing that change here".

@hebasto hebasto marked this pull request as draft October 11, 2024 19:04
@DrahtBot
Copy link
Contributor

🤔 There hasn't been much activity lately and the CI seems to be failing.

If no one reviewed the current pull request by commit hash, a rebase can be considered. While the CI failure may be a false positive, the CI hasn't been running for some time, so there may be a real issue hiding as well. A rebase triggers the latest CI and makes sure that no silent merge conflicts have snuck in.

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

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

ACK 38f93fe

(repeat my earlier comment, DrahtBot was confused)

@DrahtBot
Copy link
Contributor

🤔 There hasn't been much activity lately and the CI seems to be failing.

If no one reviewed the current pull request by commit hash, a rebase can be considered. While the CI failure may be a false positive, the CI hasn't been running for some time, so there may be a real issue hiding as well. A rebase triggers the latest CI and makes sure that no silent merge conflicts have snuck in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants