Repository: bitcoin/bitcoin (language: cpp)

Issue:
ThreadSanitizer: data race src/flatfile.cpp:47:13 in FlatFileSeq::Open(FlatFilePos const&, bool)
https://cirrus-ci.com/task/6414638208778240?logs=ci#L2908

```
 node2 2024-03-30T00:33:41.792784Z [txindex] [util/thread.cpp:20] [TraceThread] txindex thread start 
 node2 2024-03-30T00:33:41.792859Z [scheduler] [validationinterface.cpp:183] [operator()] [validation] UpdatedBlockTip: new block hash=7883788f39770ef5ae6f0f4ecee37802d50a6f0dacada65d6a8ea02f3af90c3c fork block hash=62b1edabd87390a81142c653e6e6f6543c99c6be5e63f48697d37267c0bf86fe (in IBD=true) 
 node2 2024-03-30T00:33:41.792975Z [scheduler] [validationinterface.cpp:222] [operator()] [validation] MempoolTransactionsRemovedForBlock: block height=398 txs removed=0 
 node2 2024-03-30T00:33:41.793076Z [basic block filter index] [util/thread.cpp:20] [TraceThread] basic block filter index thread start 
 node2 2024-03-30T00:33:41.793139Z [scheduler] [validationinterface.cpp:212] [operator()] [validation] BlockConnected: block hash=74b216909b0a33a9beef910bf3a85e52ba4876a83cc74a657f72c908cf623ad3 block height=398 
 node2 2024-03-30T00:33:41.793226Z [txindex] [index/base.cpp:209] [Sync] txindex is enabled at height 399 
 node2 2024-03-30T00:33:41.793341Z [txindex] [util/thread.cpp:22] [TraceThread] txindex thread exit 
 node2 2024-03-30T00:33:41.793397Z [initload] [util/thread.cpp:22] [TraceThread] initload thread exit 
 node2 2024-03-30T00:33:41.793516Z [coinstatsindex] [util/thread.cpp:20] [TraceThread] coinstatsindex thread start 
 node2 2024-03-30T00:33:41.793821Z [coinstatsindex] [index/base.cpp:209] [Sync] coinstatsindex is enabled at height 399 
 node2 2024-03-30T00:33:41.793850Z [coinstatsindex] [util/thread.cpp:22] [TraceThread] coinstatsindex thread exit 
 node2 2024-03-30T00:33:41.836832Z [http] [httpserver.cpp:306] [http_request_cb] [http] Received a POST request for / from 127.0.0.1:40794 
 test  2024-03-30T00:33:42.739000Z TestFramework (ERROR): Unexpected exception caught during testing 
                                   Traceback (most recent call last):
                                     File "/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/test_framework/test_framework.py", line 132, in main
                                       self.run_test()
                                     File "/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/feature_assumeutxo.py", line 419, in run_test
                                       self.restart_node(2, extra_args=[
                                     File "/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/test_framework/test_framework.py", line 598, in restart_node
                                       self.start_node(i, extra_args)
                                     File "/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/test_framework/test_framework.py", line 550, in start_node
                                       node.wait_for_rpc_connection()
                                     File "/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/test_framework/test_node.py", line 255, in wait_for_rpc_connection
                                       raise FailedToStartError(self._node_msg(
                                   test_framework.test_node.FailedToStartError: [node 2] bitcoind exited with status 66 during initialization. ==================
                                   WARNING: ThreadSanitizer: data race (pid=47449)
                                     Read of size 4 at 0x7b4800003b64 by thread T16:
                                       #0 FlatFileSeq::Open(FlatFilePos const&, bool) src/flatfile.cpp:47:13 (bitcoind+0x649c9f) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #1 BlockFilterIndex::CustomCommit(CDBBatch&) src/index/blockfilterindex.cpp:149:37 (bitcoind+0x687929) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #2 BaseIndex::Commit() src/index/base.cpp:222:14 (bitcoind+0x67fde7) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #3 BaseIndex::Sync() src/index/base.cpp:167:17 (bitcoind+0x67f6d0) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #4 BaseIndex::StartBackgroundSync()::$_0::operator()() const src/index/base.cpp:394:73 (bitcoind+0x6828f5) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #5 decltype(std::declval<BaseIndex::StartBackgroundSync()::$_0&>()()) std::__1::__invoke[abi:ue170006]<BaseIndex::StartBackgroundSync()::$_0&>(BaseIndex::StartBackgroundSync()::$_0&) /usr/lib/llvm-17/bin/../include/c++/v1/__type_traits/invoke.h:340:25 (bitcoind+0x6828f5)
                                       #6 void std::__1::__invoke_void_return_wrapper<void, true>::__call[abi:ue170006]<BaseIndex::StartBackgroundSync()::$_0&>(BaseIndex::StartBackgroundSync()::$_0&) /usr/lib/llvm-17/bin/../include/c++/v1/__type_traits/invoke.h:415:5 (bitcoind+0x6828f5)
                                       #7 std::__1::__function::__alloc_func<BaseIndex::StartBackgroundSync()::$_0, std::__1::allocator<BaseIndex::StartBackgroundSync()::$_0>, void ()>::operator()[abi:ue170006]() /usr/lib/llvm-17/bin/../include/c++/v1/__functional/function.h:192:16 (bitcoind+0x6828f5)
                                       #8 std::__1::__function::__func<BaseIndex::StartBackgroundSync()::$_0, std::__1::allocator<BaseIndex::StartBackgroundSync()::$_0>, void ()>::operator()() /usr/lib/llvm-17/bin/../include/c++/v1/__functional/function.h:363:12 (bitcoind+0x6828f5)
                                       #9 std::__1::__function::__value_func<void ()>::operator()[abi:ue170006]() const /usr/lib/llvm-17/bin/../include/c++/v1/__functional/function.h:517:16 (bitcoind+0xb3acd5) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #10 std::__1::function<void ()>::operator()() const /usr/lib/llvm-17/bin/../include/c++/v1/__functional/function.h:1168:12 (bitcoind+0xb3acd5)
                                       #11 util::TraceThread(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::function<void ()>) src/util/thread.cpp:21:9 (bitcoind+0xb3acd5)
                                       #12 decltype(std::declval<void (*)(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::function<void ()>)>()(std::declval<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>(), std::declval<BaseIndex::StartBackgroundSync()::$_0>())) std::__1::__invoke[abi:ue170006]<void (*)(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::function<void ()>), std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, BaseIndex::StartBackgroundSync()::$_0>(void (*&&)(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::function<void ()>), std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&&, BaseIndex::StartBackgroundSync()::$_0&&) /usr/lib/llvm-17/bin/../include/c++/v1/__type_traits/invoke.h:340:25 (bitcoind+0x6824a4) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #13 void std::__1::__thread_execute[abi:ue170006]<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void (*)(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::function<void ()>), std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, BaseIndex::StartBackgroundSync()::$_0, 2ul, 3ul>(std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void (*)(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::function<void ()>), std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, BaseIndex::StartBackgroundSync()::$_0>&, std::__1::__tuple_indices<2ul, 3ul>) /usr/lib/llvm-17/bin/../include/c++/v1/__thread/thread.h:221:5 (bitcoind+0x6824a4)
                                       #14 void* std::__1::__thread_proxy[abi:ue170006]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void (*)(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::function<void ()>), std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, BaseIndex::StartBackgroundSync()::$_0>>(void*) /usr/lib/llvm-17/bin/../include/c++/v1/__thread/thread.h:232:5 (bitcoind+0x6824a4)
                                     Previous write of size 4 at 0x7b4800003b64 by thread T1:
                                       #0 BlockFilterIndex::Write(BlockFilter const&, unsigned int, uint256 const&) src/index/blockfilterindex.cpp:287:28 (bitcoind+0x68a60a) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #1 BlockFilterIndex::CustomAppend(interfaces::BlockInfo const&) src/index/blockfilterindex.cpp:267:16 (bitcoind+0x68a101) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #2 BaseIndex::BlockConnected(ChainstateRole, std::__1::shared_ptr<CBlock const> const&, CBlockIndex const*) src/index/base.cpp:303:9 (bitcoind+0x680ce9) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #3 ValidationSignals::BlockConnected(ChainstateRole, std::__1::shared_ptr<CBlock const> const&, CBlockIndex const*)::$_0::operator()() const::'lambda'(CValidationInterface&)::operator()(CValidationInterface&) const src/validationinterface.cpp:208:79 (bitcoind+0x5f3607) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #4 void ValidationSignalsImpl::Iterate<ValidationSignals::BlockConnected(ChainstateRole, std::__1::shared_ptr<CBlock const> const&, CBlockIndex const*)::$_0::operator()() const::'lambda'(CValidationInterface&)>(ValidationSignals::BlockConnected(ChainstateRole, std::__1::shared_ptr<CBlock const> const&, CBlockIndex const*)::$_0::operator()() const::'lambda'(CValidationInterface&)&&) src/validationinterface.cpp:88:17 (bitcoind+0x5f3607)
                                       #5 ValidationSignals::BlockConnected(ChainstateRole, std::__1::shared_ptr<CBlock const> const&, CBlockIndex const*)::$_0::operator()() const src/validationinterface.cpp:208:22 (bitcoind+0x5f3607)
                                       #6 ValidationSignals::BlockConnected(ChainstateRole, std::__1::shared_ptr<CBlock const> const&, CBlockIndex const*)::$_1::operator()() const src/validationinterface.cpp:210:5 (bitcoind+0x5f3607)
                                       #7 decltype(std::declval<ValidationSignals::BlockConnected(ChainstateRole, std::__1::shared_ptr<CBlock const> const&, CBlockIndex const*)::$_1&>()()) std::__1::__invoke[abi:ue170006]<ValidationSignals::BlockConnected(ChainstateRole, std::__1::shared_ptr<CBlock const> const&, CBlockIndex const*)::$_1&>(ValidationSignals::BlockConnected(ChainstateRole, std::__1::shared_ptr<CBlock const> const&, CBlockIndex const*)::$_1&) /usr/lib/llvm-17/bin/../include/c++/v1/__type_traits/invoke.h:340:25 (bitcoind+0x5f3607)
                                       #8 void std::__1::__invoke_void_return_wrapper<void, true>::__call[abi:ue170006]<ValidationSignals::BlockConnected(ChainstateRole, std::__1::shared_ptr<CBlock const> const&, CBlockIndex const*)::$_1&>(ValidationSignals::BlockConnected(ChainstateRole, std::__1::shared_ptr<CBlock const> const&, CBlockIndex const*)::$_1&) /usr/lib/llvm-17/bin/../include/c++/v1/__type_traits/invoke.h:415:5 (bitcoind+0x5f3607)
                                       #9 std::__1::__function::__alloc_func<ValidationSignals::BlockConnected(ChainstateRole, std::__1::shared_ptr<CBlock const> const&, CBlockIndex const*)::$_1, std::__1::allocator<ValidationSignals::BlockConnected(ChainstateRole, std::__1::shared_ptr<CBlock const> const&, CBlockIndex const*)::$_1>, void ()>::operator()[abi:ue170006]() /usr/lib/llvm-17/bin/../include/c++/v1/__functional/function.h:192:16 (bitcoind+0x5f3607)
                                       #10 std::__1::__function::__func<ValidationSignals::BlockConnected(ChainstateRole, std::__1::shared_ptr<CBlock const> const&, CBlockIndex const*)::$_1, std::__1::allocator<ValidationSignals::BlockConnected(ChainstateRole, std::__1::shared_ptr<CBlock const> const&, CBlockIndex const*)::$_1>, void ()>::operator()() /usr/lib/llvm-17/bin/../include/c++/v1/__functional/function.h:363:12 (bitcoind+0x5f3607)
                                       #11 std::__1::__function::__value_func<void ()>::operator()[abi:ue170006]() const /usr/lib/llvm-17/bin/../include/c++/v1/__functional/function.h:517:16 (bitcoind+0xa3adbf) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #12 std::__1::function<void ()>::operator()() const /usr/lib/llvm-17/bin/../include/c++/v1/__functional/function.h:1168:12 (bitcoind+0xa3adbf)
                                       #13 SerialTaskRunner::ProcessQueue() src/scheduler.cpp:173:5 (bitcoind+0xa3adbf)
                                       #14 SerialTaskRunner::MaybeScheduleProcessQueue()::$_0::operator()() const src/scheduler.cpp:142:41 (bitcoind+0xa3cd15) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #15 decltype(std::declval<SerialTaskRunner::MaybeScheduleProcessQueue()::$_0&>()()) std::__1::__invoke[abi:ue170006]<SerialTaskRunner::MaybeScheduleProcessQueue()::$_0&>(SerialTaskRunner::MaybeScheduleProcessQueue()::$_0&) /usr/lib/llvm-17/bin/../include/c++/v1/__type_traits/invoke.h:340:25 (bitcoind+0xa3cd15)
                                       #16 void std::__1::__invoke_void_return_wrapper<void, true>::__call[abi:ue170006]<SerialTaskRunner::MaybeScheduleProcessQueue()::$_0&>(SerialTaskRunner::MaybeScheduleProcessQueue()::$_0&) /usr/lib/llvm-17/bin/../include/c++/v1/__type_traits/invoke.h:415:5 (bitcoind+0xa3cd15)
                                       #17 std::__1::__function::__alloc_func<SerialTaskRunner::MaybeScheduleProcessQueue()::$_0, std::__1::allocator<SerialTaskRunner::MaybeScheduleProcessQueue()::$_0>, void ()>::operator()[abi:ue170006]() /usr/lib/llvm-17/bin/../include/c++/v1/__functional/function.h:192:16 (bitcoind+0xa3cd15)
                                       #18 std::__1::__function::__func<SerialTaskRunner::MaybeScheduleProcessQueue()::$_0, std::__1::allocator<SerialTaskRunner::MaybeScheduleProcessQueue()::$_0>, void ()>::operator()() /usr/lib/llvm-17/bin/../include/c++/v1/__functional/function.h:363:12 (bitcoind+0xa3cd15)
                                       #19 std::__1::__function::__value_func<void ()>::operator()[abi:ue170006]() const /usr/lib/llvm-17/bin/../include/c++/v1/__functional/function.h:517:16 (bitcoind+0xa39b64) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #20 std::__1::function<void ()>::operator()() const /usr/lib/llvm-17/bin/../include/c++/v1/__functional/function.h:1168:12 (bitcoind+0xa39b64)
                                       #21 CScheduler::serviceQueue() src/scheduler.cpp:60:17 (bitcoind+0xa39b64)
                                       #22 AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_3::operator()() const src/init.cpp:1165:94 (bitcoind+0x1ac325) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #23 decltype(std::declval<AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_3&>()()) std::__1::__invoke[abi:ue170006]<AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_3&>(AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_3&) /usr/lib/llvm-17/bin/../include/c++/v1/__type_traits/invoke.h:340:25 (bitcoind+0x1ac325)
                                       #24 void std::__1::__invoke_void_return_wrapper<void, true>::__call[abi:ue170006]<AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_3&>(AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_3&) /usr/lib/llvm-17/bin/../include/c++/v1/__type_traits/invoke.h:415:5 (bitcoind+0x1ac325)
                                       #25 std::__1::__function::__alloc_func<AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_3, std::__1::allocator<AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_3>, void ()>::operator()[abi:ue170006]() /usr/lib/llvm-17/bin/../include/c++/v1/__functional/function.h:192:16 (bitcoind+0x1ac325)
                                       #26 std::__1::__function::__func<AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_3, std::__1::allocator<AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_3>, void ()>::operator()() /usr/lib/llvm-17/bin/../include/c++/v1/__functional/function.h:363:12 (bitcoind+0x1ac325)
                                       #27 std::__1::__function::__value_func<void ()>::operator()[abi:ue170006]() const /usr/lib/llvm-17/bin/../include/c++/v1/__functional/function.h:517:16 (bitcoind+0xb3acd5) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #28 std::__1::function<void ()>::operator()() const /usr/lib/llvm-17/bin/../include/c++/v1/__functional/function.h:1168:12 (bitcoind+0xb3acd5)
                                       #29 util::TraceThread(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::function<void ()>) src/util/thread.cpp:21:9 (bitcoind+0xb3acd5)
                                       #30 decltype(std::declval<void (*)(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::function<void ()>)>()(std::declval<char const*>(), std::declval<AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_3>())) std::__1::__invoke[abi:ue170006]<void (*)(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::function<void ()>), char const*, AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_3>(void (*&&)(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::function<void ()>), char const*&&, AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_3&&) /usr/lib/llvm-17/bin/../include/c++/v1/__type_traits/invoke.h:340:25 (bitcoind+0x1abf1c) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #31 void std::__1::__thread_execute[abi:ue170006]<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void (*)(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::function<void ()>), char const*, AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_3, 2ul, 3ul>(std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void (*)(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::function<void ()>), char const*, AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_3>&, std::__1::__tuple_indices<2ul, 3ul>) /usr/lib/llvm-17/bin/../include/c++/v1/__thread/thread.h:221:5 (bitcoind+0x1abf1c)
                                       #32 void* std::__1::__thread_proxy[abi:ue170006]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void (*)(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::function<void ()>), char const*, AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_3>>(void*) /usr/lib/llvm-17/bin/../include/c++/v1/__thread/thread.h:232:5 (bitcoind+0x1abf1c)
                                     Location is heap block of size 352 at 0x7b4800003a80 allocated by main thread:
                                       #0 operator new(unsigned long) <null> (bitcoind+0x1811ab) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #1 void* std::__1::__libcpp_operator_new[abi:ue170006]<unsigned long>(unsigned long) /usr/lib/llvm-17/bin/../include/c++/v1/new:268:10 (bitcoind+0x692f8f) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #2 std::__1::__libcpp_allocate[abi:ue170006](unsigned long, unsigned long) /usr/lib/llvm-17/bin/../include/c++/v1/new:294:10 (bitcoind+0x692f8f)
                                       #3 std::__1::allocator<std::__1::__tree_node<std::__1::__value_type<BlockFilterType, BlockFilterIndex>, void*>>::allocate[abi:ue170006](unsigned long) /usr/lib/llvm-17/bin/../include/c++/v1/__memory/allocator.h:114:38 (bitcoind+0x692f8f)
                                       #4 std::__1::allocator_traits<std::__1::allocator<std::__1::__tree_node<std::__1::__value_type<BlockFilterType, BlockFilterIndex>, void*>>>::allocate[abi:ue170006](std::__1::allocator<std::__1::__tree_node<std::__1::__value_type<BlockFilterType, BlockFilterIndex>, void*>>&, unsigned long) /usr/lib/llvm-17/bin/../include/c++/v1/__memory/allocator_traits.h:268:20 (bitcoind+0x692f8f)
                                       #5 std::__1::unique_ptr<std::__1::__tree_node<std::__1::__value_type<BlockFilterType, BlockFilterIndex>, void*>, std::__1::__tree_node_destructor<std::__1::allocator<std::__1::__tree_node<std::__1::__value_type<BlockFilterType, BlockFilterIndex>, void*>>>> std::__1::__tree<std::__1::__value_type<BlockFilterType, BlockFilterIndex>, std::__1::__map_value_compare<BlockFilterType, std::__1::__value_type<BlockFilterType, BlockFilterIndex>, std::__1::less<BlockFilterType>, true>, std::__1::allocator<std::__1::__value_type<BlockFilterType, BlockFilterIndex>>>::__construct_node<std::__1::piecewise_construct_t const&, std::__1::tuple<BlockFilterType&>, std::__1::tuple<std::__1::unique_ptr<interfaces::Chain, std::__1::default_delete<interfaces::Chain>>&&, BlockFilterType&, unsigned long&, bool&, bool&>>(std::__1::piecewise_construct_t const&, std::__1::tuple<BlockFilterType&>&&, std::__1::tuple<std::__1::unique_ptr<interfaces::Chain, std::__1::default_delete<interfaces::Chain>>&&, BlockFilterType&, unsigned long&, bool&, bool&>&&) /usr/lib/llvm-17/bin/../include/c++/v1/__tree:2143:23 (bitcoind+0x692f8f)
                                       #6 std::__1::pair<std::__1::__tree_iterator<std::__1::__value_type<BlockFilterType, BlockFilterIndex>, std::__1::__tree_node<std::__1::__value_type<BlockFilterType, BlockFilterIndex>, void*>*, long>, bool> std::__1::__tree<std::__1::__value_type<BlockFilterType, BlockFilterIndex>, std::__1::__map_value_compare<BlockFilterType, std::__1::__value_type<BlockFilterType, BlockFilterIndex>, std::__1::less<BlockFilterType>, true>, std::__1::allocator<std::__1::__value_type<BlockFilterType, BlockFilterIndex>>>::__emplace_unique_impl<std::__1::piecewise_construct_t const&, std::__1::tuple<BlockFilterType&>, std::__1::tuple<std::__1::unique_ptr<interfaces::Chain, std::__1::default_delete<interfaces::Chain>>&&, BlockFilterType&, unsigned long&, bool&, bool&>>(std::__1::piecewise_construct_t const&, std::__1::tuple<BlockFilterType&>&&, std::__1::tuple<std::__1::unique_ptr<interfaces::Chain, std::__1::default_delete<interfaces::Chain>>&&, BlockFilterType&, unsigned long&, bool&, bool&>&&) /usr/lib/llvm-17/bin/../include/c++/v1/__tree:2155:25 (bitcoind+0x692d9b) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #7 std::__1::pair<std::__1::__tree_iterator<std::__1::__value_type<BlockFilterType, BlockFilterIndex>, std::__1::__tree_node<std::__1::__value_type<BlockFilterType, BlockFilterIndex>, void*>*, long>, bool> std::__1::__tree<std::__1::__value_type<BlockFilterType, BlockFilterIndex>, std::__1::__map_value_compare<BlockFilterType, std::__1::__value_type<BlockFilterType, BlockFilterIndex>, std::__1::less<BlockFilterType>, true>, std::__1::allocator<std::__1::__value_type<BlockFilterType, BlockFilterIndex>>>::__emplace_unique[abi:ue170006]<std::__1::piecewise_construct_t const&, std::__1::tuple<BlockFilterType&>, std::__1::tuple<std::__1::unique_ptr<interfaces::Chain, std::__1::default_delete<interfaces::Chain>>&&, BlockFilterType&, unsigned long&, bool&, bool&>>(std::__1::piecewise_construct_t const&, std::__1::tuple<BlockFilterType&>&&, std::__1::tuple<std::__1::unique_ptr<interfaces::Chain, std::__1::default_delete<interfaces::Chain>>&&, BlockFilterType&, unsigned long&, bool&, bool&>&&) /usr/lib/llvm-17/bin/../include/c++/v1/__tree:1200:16 (bitcoind+0x68d833) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #8 std::__1::pair<std::__1::__map_iterator<std::__1::__tree_iterator<std::__1::__value_type<BlockFilterType, BlockFilterIndex>, std::__1::__tree_node<std::__1::__value_type<BlockFilterType, BlockFilterIndex>, void*>*, long>>, bool> std::__1::map<BlockFilterType, BlockFilterIndex, std::__1::less<BlockFilterType>, std::__1::allocator<std::__1::pair<BlockFilterType const, BlockFilterIndex>>>::emplace[abi:ue170006]<std::__1::piecewise_construct_t const&, std::__1::tuple<BlockFilterType&>, std::__1::tuple<std::__1::unique_ptr<interfaces::Chain, std::__1::default_delete<interfaces::Chain>>&&, BlockFilterType&, unsigned long&, bool&, bool&>>(std::__1::piecewise_construct_t const&, std::__1::tuple<BlockFilterType&>&&, std::__1::tuple<std::__1::unique_ptr<interfaces::Chain, std::__1::default_delete<interfaces::Chain>>&&, BlockFilterType&, unsigned long&, bool&, bool&>&&) /usr/lib/llvm-17/bin/../include/c++/v1/map:1288:24 (bitcoind+0x68d833)
                                       #9 InitBlockFilterIndex(std::__1::function<std::__1::unique_ptr<interfaces::Chain, std::__1::default_delete<interfaces::Chain>> ()>, BlockFilterType, unsigned long, bool, bool) src/index/blockfilterindex.cpp:510:36 (bitcoind+0x68d833)
                                       #10 AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*) src/init.cpp:1651:9 (bitcoind+0x1a15e7) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #11 AppInit(node::NodeContext&) src/bitcoind.cpp:228:43 (bitcoind+0x18308d) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #12 main src/bitcoind.cpp:274:10 (bitcoind+0x18308d)
                                     Thread T16 'b-basic block f' (tid=47534, running) created by thread T11 at:
                                       #0 pthread_create <null> (bitcoind+0xf7f4f) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #1 std::__1::__libcpp_thread_create[abi:ue170006](unsigned long*, void* (*)(void*), void*) /usr/lib/llvm-17/bin/../include/c++/v1/__threading_support:371:10 (bitcoind+0x682034) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #2 std::__1::thread::thread<void (*)(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::function<void ()>), std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, BaseIndex::StartBackgroundSync()::$_0, void>(void (*&&)(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::function<void ()>), std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, BaseIndex::StartBackgroundSync()::$_0&&) /usr/lib/llvm-17/bin/../include/c++/v1/__thread/thread.h:248:16 (bitcoind+0x682034)
                                       #3 BaseIndex::StartBackgroundSync() src/index/base.cpp:394:21 (bitcoind+0x682034)
                                       #4 StartIndexBackgroundSync(node::NodeContext&) src/init.cpp:2033:49 (bitcoind+0x1ab2df) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #5 AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_14::operator()() const src/init.cpp:1758:14 (bitcoind+0x1af5c5) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #6 decltype(std::declval<AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_14&>()()) std::__1::__invoke[abi:ue170006]<AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_14&>(AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_14&) /usr/lib/llvm-17/bin/../include/c++/v1/__type_traits/invoke.h:340:25 (bitcoind+0x1af5c5)
                                       #7 void std::__1::__invoke_void_return_wrapper<void, true>::__call[abi:ue170006]<AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_14&>(AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_14&) /usr/lib/llvm-17/bin/../include/c++/v1/__type_traits/invoke.h:415:5 (bitcoind+0x1af5c5)
                                       #8 std::__1::__function::__alloc_func<AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_14, std::__1::allocator<AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_14>, void ()>::operator()[abi:ue170006]() /usr/lib/llvm-17/bin/../include/c++/v1/__functional/function.h:192:16 (bitcoind+0x1af5c5)
                                       #9 std::__1::__function::__func<AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_14, std::__1::allocator<AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_14>, void ()>::operator()() /usr/lib/llvm-17/bin/../include/c++/v1/__functional/function.h:363:12 (bitcoind+0x1af5c5)
                                       #10 std::__1::__function::__value_func<void ()>::operator()[abi:ue170006]() const /usr/lib/llvm-17/bin/../include/c++/v1/__functional/function.h:517:16 (bitcoind+0xb3acd5) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #11 std::__1::function<void ()>::operator()() const /usr/lib/llvm-17/bin/../include/c++/v1/__functional/function.h:1168:12 (bitcoind+0xb3acd5)
                                       #12 util::TraceThread(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::function<void ()>) src/util/thread.cpp:21:9 (bitcoind+0xb3acd5)
                                       #13 decltype(std::declval<void (*)(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::function<void ()>)>()(std::declval<char const*>(), std::declval<AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_14>())) std::__1::__invoke[abi:ue170006]<void (*)(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::function<void ()>), char const*, AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_14>(void (*&&)(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::function<void ()>), char const*&&, AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_14&&) /usr/lib/llvm-17/bin/../include/c++/v1/__type_traits/invoke.h:340:25 (bitcoind+0x1aead2) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #14 void std::__1::__thread_execute[abi:ue170006]<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void (*)(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::function<void ()>), char const*, AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_14, 2ul, 3ul>(std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void (*)(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::function<void ()>), char const*, AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_14>&, std::__1::__tuple_indices<2ul, 3ul>) /usr/lib/llvm-17/bin/../include/c++/v1/__thread/thread.h:221:5 (bitcoind+0x1aead2)
                                       #15 void* std::__1::__thread_proxy[abi:ue170006]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void (*)(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::function<void ()>), char const*, AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_14>>(void*) /usr/lib/llvm-17/bin/../include/c++/v1/__thread/thread.h:232:5 (bitcoind+0x1aead2)
                                     Thread T1 'b-scheduler' (tid=47456, running) created by main thread at:
                                       #0 pthread_create <null> (bitcoind+0xf7f4f) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #1 std::__1::__libcpp_thread_create[abi:ue170006](unsigned long*, void* (*)(void*), void*) /usr/lib/llvm-17/bin/../include/c++/v1/__threading_support:371:10 (bitcoind+0x19c9fa) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #2 std::__1::thread::thread<void (&)(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::function<void ()>), char const (&) [10], AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_3, void>(void (&)(std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::function<void ()>), char const (&) [10], AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*)::$_3&&) /usr/lib/llvm-17/bin/../include/c++/v1/__thread/thread.h:248:16 (bitcoind+0x19c9fa)
                                       #3 AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*) src/init.cpp:1165:34 (bitcoind+0x19c9fa)
                                       #4 AppInit(node::NodeContext&) src/bitcoind.cpp:228:43 (bitcoind+0x18308d) (BuildId: 994f604f928124359e165db86502aa34e11056bc)
                                       #5 main src/bitcoind.cpp:274:10 (bitcoind+0x18308d)
                                   SUMMARY: ThreadSanitizer: data race src/flatfile.cpp:47:13 in FlatFileSeq::Open(FlatFilePos const&, bool)
                                   ==================
                                   ************************


Discussion / hints:

Fix patch:
diff --git a/src/index/base.cpp b/src/index/base.cpp
index 13d8ba5a01095..a203ce4a9f381 100644
--- a/src/index/base.cpp
+++ b/src/index/base.cpp
@@ -162,9 +162,9 @@ void BaseIndex::Sync()
             const CBlockIndex* pindex_next = WITH_LOCK(cs_main, return NextSyncBlock(pindex, m_chainstate->m_chain));
             if (!pindex_next) {
                 SetBestBlockIndex(pindex);
-                m_synced = true;
                 // No need to handle errors in Commit. See rationale above.
                 Commit();
+                m_synced = true;
                 break;
             }
             if (pindex_next->pprev != pindex && !Rewind(pindex, pindex_next->pprev)) {


Test patch: