From 6d3689fcf6cff397187028344570489db3e6ecf4 Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Thu, 26 Nov 2020 14:16:10 +0100 Subject: [PATCH 1/3] sync: print proper lock order location when double lock is detected 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. ``` --- src/sync.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sync.cpp b/src/sync.cpp index 2e431720e6..2160940952 100644 --- a/src/sync.cpp +++ b/src/sync.cpp @@ -150,7 +150,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"); From a21dc469ccf076ca3b07b1adbd8bf667145f1c44 Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Thu, 26 Nov 2020 14:36:58 +0100 Subject: [PATCH 2/3] sync: const-qualify the argument of double_lock_detected() It is not modified in the function, so should be `const`. --- src/sync.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sync.cpp b/src/sync.cpp index 2160940952..f07916041a 100644 --- a/src/sync.cpp +++ b/src/sync.cpp @@ -139,7 +139,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"); From db058efeb0821cb5022e3b29e0aff3627d7aaf83 Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Thu, 26 Nov 2020 14:39:12 +0100 Subject: [PATCH 3/3] sync: use HasReason() in double lock tests `HasReason()` is shorter than a lambda function. --- src/test/sync_tests.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/test/sync_tests.cpp b/src/test/sync_tests.cpp index 6c14867211..14145ced7e 100644 --- a/src/test/sync_tests.cpp +++ b/src/test/sync_tests.cpp @@ -50,10 +50,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)); }