Skip to content

Commit 7f0f01f

Browse files
author
MarcoFalke
committed
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
2 parents 283f22c + db058ef commit 7f0f01f

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
@@ -139,7 +139,7 @@ static void potential_deadlock_detected(const LockPair& mismatch, const LockStac
139139
throw std::logic_error(strprintf("potential deadlock detected: %s -> %s -> %s", mutex_b, mutex_a, mutex_b));
140140
}
141141

142-
static void double_lock_detected(const void* mutex, LockStack& lock_stack)
142+
static void double_lock_detected(const void* mutex, const LockStack& lock_stack)
143143
{
144144
LogPrintf("DOUBLE LOCK DETECTED\n");
145145
LogPrintf("Lock order:\n");
@@ -150,7 +150,9 @@ static void double_lock_detected(const void* mutex, LockStack& lock_stack)
150150
LogPrintf(" %s\n", i.second.ToString());
151151
}
152152
if (g_debug_lockorder_abort) {
153-
tfm::format(std::cerr, "Assertion failed: detected double lock at %s:%i, details in debug log.\n", __FILE__, __LINE__);
153+
tfm::format(std::cerr,
154+
"Assertion failed: detected double lock for %s, details in debug log.\n",
155+
lock_stack.back().second.ToString());
154156
abort();
155157
}
156158
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
@@ -50,10 +50,8 @@ void TestDoubleLock(bool should_throw)
5050
MutexType m;
5151
ENTER_CRITICAL_SECTION(m);
5252
if (should_throw) {
53-
BOOST_CHECK_EXCEPTION(
54-
TestDoubleLock2(m), std::logic_error, [](const std::logic_error& e) {
55-
return strcmp(e.what(), "double lock detected") == 0;
56-
});
53+
BOOST_CHECK_EXCEPTION(TestDoubleLock2(m), std::logic_error,
54+
HasReason("double lock detected"));
5755
} else {
5856
BOOST_CHECK_NO_THROW(TestDoubleLock2(m));
5957
}

0 commit comments

Comments
 (0)