Skip to content

Commit

Permalink
Merge bitcoin#20507: sync: print proper lock order location when doub…
Browse files Browse the repository at this point in the history
…le lock is detected

db058ef sync: use HasReason() in double lock tests (Vasil Dimov)
a21dc46 sync: const-qualify the argument of double_lock_detected() (Vasil Dimov)
6d3689f sync: print proper lock order location when double lock is detected (Vasil Dimov)

Pull request description:

  Before:
  ```
  Assertion failed: detected double lock at src/sync.cpp:153, details in debug log.
  ```

  After:
  ```
  Assertion failed: detected double lock for 'm' in src/test/sync_tests.cpp:40 (in thread ''), details in debug log.
  ```

ACKs for top commit:
  jonasschnelli:
    utACK db058ef
  ajtowns:
    ACK db058ef
  hebasto:
    ACK db058ef, tested on Linux Mint 20 (x86_64).

Tree-SHA512: 452ddb9a14e44bb174135b39f2219c76eadbb8a6c0e80d64a25f995780d6dbc7b570d9902616db94dbfabaee197b5828ba3475171a68240ac0958fb203a7acdb
  • Loading branch information
MarcoFalke authored and vijaydasmp committed Feb 4, 2024
1 parent fa60603 commit dfdbdfc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static void potential_deadlock_detected(const LockPair& mismatch, const LockStac
throw std::logic_error(strprintf("potential deadlock detected: %s -> %s -> %s", mutex_b, mutex_a, mutex_b));
}

static void double_lock_detected(const void* mutex, LockStack& lock_stack)
static void double_lock_detected(const void* mutex, const LockStack& lock_stack)
{
LogPrintf("DOUBLE LOCK DETECTED\n");
LogPrintf("Lock order:\n");
Expand All @@ -151,7 +151,9 @@ static void double_lock_detected(const void* mutex, LockStack& lock_stack)
LogPrintf(" %s\n", i.second.ToString());
}
if (g_debug_lockorder_abort) {
tfm::format(std::cerr, "Assertion failed: detected double lock at %s:%i, details in debug log.\n", __FILE__, __LINE__);
tfm::format(std::cerr,
"Assertion failed: detected double lock for %s, details in debug log.\n",
lock_stack.back().second.ToString());
abort();
}
throw std::logic_error("double lock detected");
Expand Down
6 changes: 2 additions & 4 deletions src/test/sync_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ void TestDoubleLock(bool should_throw)
MutexType m;
ENTER_CRITICAL_SECTION(m);
if (should_throw) {
BOOST_CHECK_EXCEPTION(
TestDoubleLock2(m), std::logic_error, [](const std::logic_error& e) {
return strcmp(e.what(), "double lock detected") == 0;
});
BOOST_CHECK_EXCEPTION(TestDoubleLock2(m), std::logic_error,
HasReason("double lock detected"));
} else {
BOOST_CHECK_NO_THROW(TestDoubleLock2(m));
}
Expand Down

0 comments on commit dfdbdfc

Please sign in to comment.