Skip to content

Commit 18500ea

Browse files
MarcoFalkePastaPastaPasta
authored andcommitted
Merge bitcoin#20507: sync: print proper lock order location when double 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
1 parent 8038be1 commit 18500ea

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/sync.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static void potential_deadlock_detected(const LockPair& mismatch, const LockStac
140140
throw std::logic_error(strprintf("potential deadlock detected: %s -> %s -> %s", mutex_b, mutex_a, mutex_b));
141141
}
142142

143-
static void double_lock_detected(const void* mutex, LockStack& lock_stack)
143+
static void double_lock_detected(const void* mutex, const LockStack& lock_stack)
144144
{
145145
LogPrintf("DOUBLE LOCK DETECTED\n");
146146
LogPrintf("Lock order:\n");
@@ -151,7 +151,9 @@ static void double_lock_detected(const void* mutex, LockStack& lock_stack)
151151
LogPrintf(" %s\n", i.second.ToString());
152152
}
153153
if (g_debug_lockorder_abort) {
154-
tfm::format(std::cerr, "Assertion failed: detected double lock at %s:%i, details in debug log.\n", __FILE__, __LINE__);
154+
tfm::format(std::cerr,
155+
"Assertion failed: detected double lock for %s, details in debug log.\n",
156+
lock_stack.back().second.ToString());
155157
abort();
156158
}
157159
throw std::logic_error("double lock detected");

src/test/sync_tests.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,8 @@ void TestDoubleLock(bool should_throw)
6262
MutexType m;
6363
ENTER_CRITICAL_SECTION(m);
6464
if (should_throw) {
65-
BOOST_CHECK_EXCEPTION(
66-
TestDoubleLock2(m), std::logic_error, [](const std::logic_error& e) {
67-
return strcmp(e.what(), "double lock detected") == 0;
68-
});
65+
BOOST_CHECK_EXCEPTION(TestDoubleLock2(m), std::logic_error,
66+
HasReason("double lock detected"));
6967
} else {
7068
BOOST_CHECK_NO_THROW(TestDoubleLock2(m));
7169
}

0 commit comments

Comments
 (0)