Skip to content

Conversation

@hebasto
Copy link
Member

@hebasto hebasto commented Apr 14, 2021

This PR is a #21669 follow up, and fixes locally running make check.

This change fixes locally running tests.
@maflcko
Copy link
Member

maflcko commented Apr 14, 2021

Looks like your compiler inlined the whole function and thus can not apply the suppression?

cr ACK f2ef5a8

An alternative would be to simply avoid the intentional lock-order-inversion.

diff --git a/src/test/sync_tests.cpp b/src/test/sync_tests.cpp
index 3e4d1dac9e..737cf166cd 100644
--- a/src/test/sync_tests.cpp
+++ b/src/test/sync_tests.cpp
@@ -17,6 +17,11 @@ void TestPotentialDeadLockDetected(MutexType& mutex1, MutexType& mutex2)
         LOCK2(mutex1, mutex2);
     }
     BOOST_CHECK(LockStackEmpty());
+#ifndef DEBUG_LOCKORDER
+    // Return early to avoid the lock-order-inversion.
+    // Sanitizers different from our own DEBUG_LOCKORDER sanitizer would otherwise warn about this.
+    return;
+#endif
     bool error_thrown = false;
     try {
         LOCK2(mutex2, mutex1);
@@ -25,11 +30,7 @@ void TestPotentialDeadLockDetected(MutexType& mutex1, MutexType& mutex2)
         error_thrown = true;
     }
     BOOST_CHECK(LockStackEmpty());
-    #ifdef DEBUG_LOCKORDER
     BOOST_CHECK(error_thrown);
-    #else
-    BOOST_CHECK(!error_thrown);
-    #endif
 }
 
 #ifdef DEBUG_LOCKORDER
diff --git a/test/sanitizer_suppressions/tsan b/test/sanitizer_suppressions/tsan
index e2c79d56c5..0213dc58fc 100644
--- a/test/sanitizer_suppressions/tsan
+++ b/test/sanitizer_suppressions/tsan
@@ -15,9 +15,6 @@ race:bitcoin-qt
 # deadlock (TODO fix)
 deadlock:CChainState::ConnectTip
 
-# Intentional deadlock in tests
-deadlock:TestPotentialDeadLockDetected
-
 # Wildcard for all gui tests, should be replaced with non-wildcard suppressions
 race:src/qt/test/*
 deadlock:src/qt/test/*

(diff untested and uncompiled)

@maflcko maflcko changed the title test: Fix TSan suppression test: Fix TestPotentialDeadLockDetected suppression Apr 14, 2021
@hebasto
Copy link
Member Author

hebasto commented Apr 14, 2021

The suggested diff skips a part of the test, particularly BOOST_CHECK(!error_thrown);, that seems unwanted.

@maflcko
Copy link
Member

maflcko commented Apr 14, 2021

What is the value of checking that two locks can be successfully taken both in the order a-b and in the order b-a. We don't use that anywhere, so it seems odd to have a test for it.

@hebasto
Copy link
Member Author

hebasto commented Apr 14, 2021

@ryanofsky @vasild What do you think?

@maflcko
Copy link
Member

maflcko commented Apr 14, 2021

( Test added by @ryanofsky in commit 41b88e9 )

@ryanofsky
Copy link
Contributor

I'm not sure what question's being asked, but I'm happy to review any change.

Intention of #else clause in the referenced commit is to check that process will not unnecessarily throw an exception and potentially crash when DEBUG_LOCKORDER is disabled. Crashes can be bad, so it is good to verify that a crash won't happen when crashes are supposed to be disabled just because locks are acquired in a theoretically-bad ordering that wouldn't cause an actual problem.

But I don't think it's a big deal to drop the check if it's too expensive because it can't be done with sanitizers enabled and would require a separate build. Or any other reason. It's not a very important check.

@ryanofsky
Copy link
Contributor

Oh, I understand better now. This PR is fixing a broken suppression, and Marco's saying it is easier to skip the check that requires the suppression instead of fixing the suppression.

I have no opinion on what's easier. I think the check does serve a purpose, but it's also not very important.

@maflcko maflcko merged commit 773f8c1 into bitcoin:master Apr 14, 2021
@hebasto hebasto deleted the 210414-deadlock branch April 14, 2021 14:58
@vasild
Copy link
Contributor

vasild commented Apr 14, 2021

So, the problem this PR fixed is that TestPotentialDeadLockDetected() was inlined and thus did not match the suppression deadlock:TestPotentialDeadLockDetected? Why it started happening now?

@hebasto
Copy link
Member Author

hebasto commented Apr 14, 2021

Why it started happening now?

clang-12?

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Apr 14, 2021
f2ef5a8 test: Fix TSan suppression (Hennadii Stepanov)

Pull request description:

  This PR is a bitcoin#21669 follow up, and fixes [locally running `make check`](bitcoin#21669 (comment)).

ACKs for top commit:
  MarcoFalke:
    cr ACK f2ef5a8

Tree-SHA512: bb0c4d1707c6194358d2e9abfed5aa8dd487e014199025fb89f6e5a66d774af041b46a03358a9a5412e1683675c05c42a3b719217d940412ee3fe1ed18a5274c
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 19, 2021
f2ef5a8 test: Fix TSan suppression (Hennadii Stepanov)

Pull request description:

  This PR is a bitcoin#21669 follow up, and fixes [locally running `make check`](bitcoin#21669 (comment)).

ACKs for top commit:
  MarcoFalke:
    cr ACK f2ef5a8

Tree-SHA512: bb0c4d1707c6194358d2e9abfed5aa8dd487e014199025fb89f6e5a66d774af041b46a03358a9a5412e1683675c05c42a3b719217d940412ee3fe1ed18a5274c
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants