Skip to content

Commit bbe9cf4

Browse files
committed
test: Improve "potential deadlock detected" exception message
1 parent 3559934 commit bbe9cf4

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/sync.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,25 @@ static void potential_deadlock_detected(const LockPair& mismatch, const LockStac
114114
}
115115
LogPrintf(" %s\n", i.second.ToString());
116116
}
117+
118+
std::string mutex_a, mutex_b;
117119
LogPrintf("Current lock order is:\n");
118120
for (const LockStackItem& i : s2) {
119121
if (i.first == mismatch.first) {
120122
LogPrintf(" (1)"); /* Continued */
123+
mutex_a = i.second.Name();
121124
}
122125
if (i.first == mismatch.second) {
123126
LogPrintf(" (2)"); /* Continued */
127+
mutex_b = i.second.Name();
124128
}
125129
LogPrintf(" %s\n", i.second.ToString());
126130
}
127131
if (g_debug_lockorder_abort) {
128132
tfm::format(std::cerr, "Assertion failed: detected inconsistent lock order at %s:%i, details in debug log.\n", __FILE__, __LINE__);
129133
abort();
130134
}
131-
throw std::logic_error("potential deadlock detected");
135+
throw std::logic_error(strprintf("potential deadlock detected: %s -> %s -> %s", mutex_b, mutex_a, mutex_b));
132136
}
133137

134138
static void push_lock(void* c, const CLockLocation& locklocation)

src/test/sync_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void TestPotentialDeadLockDetected(MutexType& mutex1, MutexType& mutex2)
1818
try {
1919
LOCK2(mutex2, mutex1);
2020
} catch (const std::logic_error& e) {
21-
BOOST_CHECK_EQUAL(e.what(), "potential deadlock detected");
21+
BOOST_CHECK_EQUAL(e.what(), "potential deadlock detected: mutex1 -> mutex2 -> mutex1");
2222
error_thrown = true;
2323
}
2424
#ifdef DEBUG_LOCKORDER

0 commit comments

Comments
 (0)