test: Potential deadlock in wallet_tests #19955

issue narula opened this issue on September 14, 2020
  1. narula commented at 8:21 PM on September 14, 2020: contributor

    Building on master 06dbbe76dd027e924eb95ffc4b409daffaefe61b on x86_64 Ubuntu 18.04:

    neha@mumford:~/src/bitcoin master$ echo $TSAN_OPTIONS
    suppressions=/home/neha/src/bitcoin/test/sanitizer_suppressions/tsan:halt_on_error=1:external_symbolizer_path=/home/neha/bin/llvm-symbolizer:second_deadlock_stack=1
    neha@mumford:~/src/bitcoin master$ src/test/test_bitcoin --run_test=wallet_tests
    Running 13 test cases...
    ==================
    WARNING: ThreadSanitizer: lock-order-inversion (potential deadlock) (pid=88519)
      Cycle in lock order graph: M133494 (0x7ffd954d2730) => M131981 (0x55f91a9da228) => M133494
    
      Mutex M131981 acquired here while holding mutex M133494 in main thread:
        [#0](/bitcoin-bitcoin/0/) pthread_mutex_lock <null> (test_bitcoin+0x29f747)
        [#1](/bitcoin-bitcoin/1/) __gthread_mutex_lock(pthread_mutex_t*) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0/bits/gthr-default.h:748:12 (test_bitcoin+0x3f07e3)
        [#2](/bitcoin-bitcoin/2/) __gthread_recursive_mutex_lock(pthread_mutex_t*) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0/bits/gthr-default.h:810:10 (test_bitcoin+0x3f0765)
        [#3](/bitcoin-bitcoin/3/) std::recursive_mutex::lock() /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/mutex:107:17 (test_bitcoin+0x3f8715)
        [#4](/bitcoin-bitcoin/4/) std::unique_lock<std::recursive_mutex>::lock() /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/std_mutex.h:267:17 (test_bitcoin+0x3f867e)
        [#5](/bitcoin-bitcoin/5/) UniqueLock<AnnotatedMixin<std::recursive_mutex>, std::unique_lock<std::recursive_mutex> >::Enter(char const*, char const*, int) /home/neha/src/bitcoin/src/./sync.h:143:19 (test_bitcoin+0x3f81f7)
        [#6](/bitcoin-bitcoin/6/) UniqueLock<AnnotatedMixin<std::recursive_mutex>, std::unique_lock<std::recursive_mutex> >::UniqueLock(AnnotatedMixin<std::recursive_mutex>&, char const*, char const*, int, bool) /home/neha/src/bitcoin/src/./sync.h:164:13 (test_bitcoin+0x3f7d21)
        [#7](/bitcoin-bitcoin/7/) ChainActive() /home/neha/src/bitcoin/src/validation.cpp:114:5 (test_bitcoin+0x126a7f4)
        [#8](/bitcoin-bitcoin/8/) wallet_tests::scan_for_wallet_transactions::test_method() /home/neha/src/bitcoin/src/wallet/test/wallet_tests.cpp:164:42 (test_bitcoin+0xc07caf)
        [#9](/bitcoin-bitcoin/9/) wallet_tests::scan_for_wallet_transactions_invoker() /home/neha/src/bitcoin/src/wallet/test/wallet_tests.cpp:78:1 (test_bitcoin+0xc0534e)
        [#10](/bitcoin-bitcoin/10/) boost::detail::function::void_function_invoker0<void (*)(), void>::invoke(boost::detail::function::function_buffer&) /usr/include/boost/function/function_template.hpp:118:11 (test_bitcoin+0x3b7cca)
        [#11](/bitcoin-bitcoin/11/) boost::detail::function::function_obj_invoker0<boost::detail::forward, int>::invoke(boost::detail::function::function_buffer&) <null> (libboost_unit_test_framework.so.1.65.1+0x4b2cd)
        [#12](/bitcoin-bitcoin/12/) __libc_start_main /build/glibc-2ORdQG/glibc-2.27/csu/../csu/libc-start.c:310 (libc.so.6+0x21b96)
    
      Mutex M133494 previously acquired by the same thread here:
        [#0](/bitcoin-bitcoin/0/) pthread_mutex_lock <null> (test_bitcoin+0x29f747)
        [#1](/bitcoin-bitcoin/1/) __gthread_mutex_lock(pthread_mutex_t*) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0/bits/gthr-default.h:748:12 (test_bitcoin+0x3f07e3)
        [#2](/bitcoin-bitcoin/2/) __gthread_recursive_mutex_lock(pthread_mutex_t*) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0/bits/gthr-default.h:810:10 (test_bitcoin+0x3f0765)
        [#3](/bitcoin-bitcoin/3/) std::recursive_mutex::lock() /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/mutex:107:17 (test_bitcoin+0x3f8715)
        [#4](/bitcoin-bitcoin/4/) std::unique_lock<std::recursive_mutex>::lock() /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/std_mutex.h:267:17 (test_bitcoin+0x3f867e)
        [#5](/bitcoin-bitcoin/5/) UniqueLock<AnnotatedMixin<std::recursive_mutex>, std::unique_lock<std::recursive_mutex> >::Enter(char const*, char const*, int) /home/neha/src/bitcoin/src/./sync.h:143:19 (test_bitcoin+0x3f81f7)
        [#6](/bitcoin-bitcoin/6/) UniqueLock<AnnotatedMixin<std::recursive_mutex>, std::unique_lock<std::recursive_mutex> >::UniqueLock(AnnotatedMixin<std::recursive_mutex>&, char const*, char const*, int, bool) /home/neha/src/bitcoin/src/./sync.h:164:13 (test_bitcoin+0x3f7d21)
        [#7](/bitcoin-bitcoin/7/) wallet_tests::scan_for_wallet_transactions::test_method() /home/neha/src/bitcoin/src/wallet/test/wallet_tests.cpp:163:13 (test_bitcoin+0xc07ca5)
        [#8](/bitcoin-bitcoin/8/) wallet_tests::scan_for_wallet_transactions_invoker() /home/neha/src/bitcoin/src/wallet/test/wallet_tests.cpp:78:1 (test_bitcoin+0xc0534e)
        [#9](/bitcoin-bitcoin/9/) boost::detail::function::void_function_invoker0<void (*)(), void>::invoke(boost::detail::function::function_buffer&) /usr/include/boost/function/function_template.hpp:118:11 (test_bitcoin+0x3b7cca)
        [#10](/bitcoin-bitcoin/10/) boost::detail::function::function_obj_invoker0<boost::detail::forward, int>::invoke(boost::detail::function::function_buffer&) <null> (libboost_unit_test_framework.so.1.65.1+0x4b2cd)
        [#11](/bitcoin-bitcoin/11/) __libc_start_main /build/glibc-2ORdQG/glibc-2.27/csu/../csu/libc-start.c:310 (libc.so.6+0x21b96)
    
      Mutex M133494 acquired here while holding mutex M131981 in main thread:
        [#0](/bitcoin-bitcoin/0/) pthread_mutex_lock <null> (test_bitcoin+0x29f747)
        [#1](/bitcoin-bitcoin/1/) __gthread_mutex_lock(pthread_mutex_t*) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0/bits/gthr-default.h:748:12 (test_bitcoin+0x3f07e3)
        [#2](/bitcoin-bitcoin/2/) __gthread_recursive_mutex_lock(pthread_mutex_t*) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0/bits/gthr-default.h:810:10 (test_bitcoin+0x3f0765)
        [#3](/bitcoin-bitcoin/3/) std::recursive_mutex::lock() /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/mutex:107:17 (test_bitcoin+0x3f8715)
        [#4](/bitcoin-bitcoin/4/) std::unique_lock<std::recursive_mutex>::lock() /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/std_mutex.h:267:17 (test_bitcoin+0x3f867e)
        [#5](/bitcoin-bitcoin/5/) UniqueLock<AnnotatedMixin<std::recursive_mutex>, std::unique_lock<std::recursive_mutex> >::Enter(char const*, char const*, int) /home/neha/src/bitcoin/src/./sync.h:143:19 (test_bitcoin+0x3f81f7)
        [#6](/bitcoin-bitcoin/6/) UniqueLock<AnnotatedMixin<std::recursive_mutex>, std::unique_lock<std::recursive_mutex> >::UniqueLock(AnnotatedMixin<std::recursive_mutex>&, char const*, char const*, int, bool) /home/neha/src/bitcoin/src/./sync.h:164:13 (test_bitcoin+0x3f7d21)
        [#7](/bitcoin-bitcoin/7/) BlockAssembler::CreateNewBlock(CScript const&) /home/neha/src/bitcoin/src/miner.cpp:119:5 (test_bitcoin+0xdce885)
        [#8](/bitcoin-bitcoin/8/) TestChain100Setup::CreateAndProcessBlock(std::vector<CMutableTransaction, std::allocator<CMutableTransaction> > const&, CScript const&) /home/neha/src/bitcoin/src/test/util/setup_common.cpp:214:60 (test_bitcoin+0xcabcb5)
        [#9](/bitcoin-bitcoin/9/) wallet_tests::importwallet_rescan::test_method() /home/neha/src/bitcoin/src/wallet/test/wallet_tests.cpp:249:34 (test_bitcoin+0xc0d18b)
        [#10](/bitcoin-bitcoin/10/) wallet_tests::importwallet_rescan_invoker() /home/neha/src/bitcoin/src/wallet/test/wallet_tests.cpp:243:1 (test_bitcoin+0xc0cc2e)
        [#11](/bitcoin-bitcoin/11/) boost::detail::function::void_function_invoker0<void (*)(), void>::invoke(boost::detail::function::function_buffer&) /usr/include/boost/function/function_template.hpp:118:11 (test_bitcoin+0x3b7cca)
        [#12](/bitcoin-bitcoin/12/) boost::detail::function::function_obj_invoker0<boost::detail::forward, int>::invoke(boost::detail::function::function_buffer&) <null> (libboost_unit_test_framework.so.1.65.1+0x4b2cd)
        [#13](/bitcoin-bitcoin/13/) __libc_start_main /build/glibc-2ORdQG/glibc-2.27/csu/../csu/libc-start.c:310 (libc.so.6+0x21b96)
    
      Mutex M131981 previously acquired by the same thread here:
        [#0](/bitcoin-bitcoin/0/) pthread_mutex_lock <null> (test_bitcoin+0x29f747)
        [#1](/bitcoin-bitcoin/1/) __gthread_mutex_lock(pthread_mutex_t*) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0/bits/gthr-default.h:748:12 (test_bitcoin+0x3f07e3)
        [#2](/bitcoin-bitcoin/2/) __gthread_recursive_mutex_lock(pthread_mutex_t*) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0/bits/gthr-default.h:810:10 (test_bitcoin+0x3f0765)
        [#3](/bitcoin-bitcoin/3/) std::recursive_mutex::lock() /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/mutex:107:17 (test_bitcoin+0x3f8715)
        [#4](/bitcoin-bitcoin/4/) std::unique_lock<std::recursive_mutex>::lock() /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/std_mutex.h:267:17 (test_bitcoin+0x3f867e)
        [#5](/bitcoin-bitcoin/5/) UniqueLock<AnnotatedMixin<std::recursive_mutex>, std::unique_lock<std::recursive_mutex> >::Enter(char const*, char const*, int) /home/neha/src/bitcoin/src/./sync.h:143:19 (test_bitcoin+0x3f81f7)
        [#6](/bitcoin-bitcoin/6/) UniqueLock<AnnotatedMixin<std::recursive_mutex>, std::unique_lock<std::recursive_mutex> >::UniqueLock(AnnotatedMixin<std::recursive_mutex>&, char const*, char const*, int, bool) /home/neha/src/bitcoin/src/./sync.h:164:13 (test_bitcoin+0x3f7d21)
        [#7](/bitcoin-bitcoin/7/) BlockAssembler::CreateNewBlock(CScript const&) /home/neha/src/bitcoin/src/miner.cpp:119:5 (test_bitcoin+0xdce827)
        [#8](/bitcoin-bitcoin/8/) TestChain100Setup::CreateAndProcessBlock(std::vector<CMutableTransaction, std::allocator<CMutableTransaction> > const&, CScript const&) /home/neha/src/bitcoin/src/test/util/setup_common.cpp:214:60 (test_bitcoin+0xcabcb5)
        [#9](/bitcoin-bitcoin/9/) wallet_tests::importwallet_rescan::test_method() /home/neha/src/bitcoin/src/wallet/test/wallet_tests.cpp:249:34 (test_bitcoin+0xc0d18b)
        [#10](/bitcoin-bitcoin/10/) wallet_tests::importwallet_rescan_invoker() /home/neha/src/bitcoin/src/wallet/test/wallet_tests.cpp:243:1 (test_bitcoin+0xc0cc2e)
        [#11](/bitcoin-bitcoin/11/) boost::detail::function::void_function_invoker0<void (*)(), void>::invoke(boost::detail::function::function_buffer&) /usr/include/boost/function/function_template.hpp:118:11 (test_bitcoin+0x3b7cca)
        [#12](/bitcoin-bitcoin/12/) boost::detail::function::function_obj_invoker0<boost::detail::forward, int>::invoke(boost::detail::function::function_buffer&) <null> (libboost_unit_test_framework.so.1.65.1+0x4b2cd)
        [#13](/bitcoin-bitcoin/13/) __libc_start_main /build/glibc-2ORdQG/glibc-2.27/csu/../csu/libc-start.c:310 (libc.so.6+0x21b96)
    
    SUMMARY: ThreadSanitizer: lock-order-inversion (potential deadlock) (/home/neha/src/bitcoin/src/test/test_bitcoin+0x29f747) in pthread_mutex_lock
    ==================
    

    Running just scan_for_wallet_transactions or importwallet_rescan alone does not result in this error. Perhaps another thing to add to the suppressions file?

    neha@mumford:~/src/bitcoin master$ src/test/test_bitcoin --run_test=wallet_tests/scan_for_wallet_transactions
    Running 1 test case...
    
    *** No errors detected
    neha@mumford:~/src/bitcoin master$ src/test/test_bitcoin --run_test=wallet_tests/importwallet_rescan
    Running 1 test case...
    
    *** No errors detected
    

    Related to #19049

  2. narula added the label Bug on Sep 14, 2020
  3. hebasto commented at 3:49 PM on September 19, 2020: member

    @narula Does this issue happen for pre-#19775 code?

    On Linux Mint 20 (Ubuntu 20.04 code base):

    $ src/test/test_bitcoin --run_test=wallet_tests
    Running 13 test cases...
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    
    *** No errors detected
    
  4. narula commented at 4:30 PM on September 19, 2020: contributor

    @narula Does this issue happen for pre-#19775 code? @hebasto It does not! I get the same results as you:

    neha@mumford:~/src/bitcoin2 (HEAD detached at 3de365e4f1)$ src/test/test_bitcoin --run_test=wallet_tests
    Running 13 test cases...
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    WARNING: too long mutex cycle found
    
    *** No errors detected
    

    I configured without the gui so I'm imagining it ran fewer tests...

  5. hebasto commented at 7:39 PM on September 19, 2020: member

    @narula

    Building on master 06dbbe7 on x86_64 Ubuntu 18.04:

    I cannot reproduce it on Linux Mint 19.3 (x86_64, Ubuntu 18.04 code base).

  6. willcl-ark commented at 12:58 PM on February 7, 2023: contributor

    Is this still an issue? I have just had a go on 22.10 and cannot reproduce:

    $ set TSAN_OPTIONS "suppressions=/home/will/src/bitcoin/test/sanitizer_suppressions/tsan:halt_on_error=1:external_symbolizer_path=/usr/bin/llvm-symbolizer:second_deadlock_stack=1"
    $ ./configure --with-sanitizers=thread
    $ make -j16
    $ src/test/test_bitcoin --run_test=wallet_tests
    Running 16 test cases...
    
    *** No errors detected
    

    Edit: tested after building with both gcc and clang and both seemed ok.

  7. maflcko commented at 1:07 PM on February 7, 2023: member

    Is this still an issue with a recent version of Bitcoin Core? If yes, what are the steps to reproduce, ideally starting from a fresh install of the operating system, and denoting the compiler version (clang/gcc), and libraries, etc.

  8. maflcko closed this on Feb 7, 2023

  9. bitcoin locked this on Feb 7, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 18:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me