AssumeUTXO snapshot completion during startup can start an index thread twice #37079

issue l0rinc opened this issue on December 2, 2026
  1. l0rinc commented at 9:14 PM on December 2, 2026: contributor

    If importing historical blocks finishes background validation before the normal startup index step, the snapshot-completion callback starts each index thread first. Startup then calls StartBackgroundSync() again, assigns over the still-joinable thread, and aborts.

    <details> <summary>Reproducer</summary>

    This calls StartBackgroundSync() twice directly, as the two startup paths do.

    diff --git a/src/test/baseindex_tests.cpp b/src/test/baseindex_tests.cpp
    index 28ed5f8614..c49c0c4555 100644
    --- a/src/test/baseindex_tests.cpp
    +++ b/src/test/baseindex_tests.cpp
    @@ -2,6 +2,8 @@
     // Distributed under the MIT software license, see the accompanying
     // file COPYING or http://www.opensource.org/licenses/mit-license.php.
     
    +#include <bitcoin-build-config.h>
    +
     #include <addresstype.h>
     #include <blockfilter.h>
     #include <chain.h>
    @@ -39,6 +41,12 @@
     #include <memory>
     #include <string>
     #include <thread>
    +
    +#if HAVE_DECL_FORK
    +#include <csignal>
    +#include <sys/wait.h>
    +#include <unistd.h>
    +#endif
     #include <utility>
     #include <vector>
     
    @@ -235,4 +243,24 @@ BOOST_FIXTURE_TEST_CASE(index_reorg_crash, TestChain100Setup)
         StopIndex(index, m_node);
     }
     
    +#if HAVE_DECL_FORK
    +BOOST_FIXTURE_TEST_CASE(baseindex_double_start_aborts, TestChain100Setup)
    +{
    +    const pid_t pid{fork()};
    +    BOOST_REQUIRE(pid >= 0);
    +    if (pid == 0) {
    +        std::signal(SIGABRT, SIG_DFL);
    +        TxIndex index{interfaces::MakeChain(m_node), /*n_cache_size=*/1_MiB, /*f_memory=*/true};
    +        if (!index.Init() || !index.StartBackgroundSync()) _exit(1);
    +        if (!index.StartBackgroundSync()) _exit(2);
    +        _exit(3);
    +    }
    +
    +    int status{0};
    +    BOOST_REQUIRE_EQUAL(waitpid(pid, &status, 0), pid);
    +    BOOST_CHECK(WIFSIGNALED(status));
    +    BOOST_CHECK_EQUAL(WTERMSIG(status), SIGABRT); // TODO: Starting an index twice must not abort
    +}
    +#endif
    +
     BOOST_AUTO_TEST_SUITE_END()
    

    </details>

    The direct fix would be to let only one of the two paths start each index thread, but given that AssumeUTXO fixes haven't attracted much review, I'm proposing to remove AssumeUTXO entirely in #36598 instead.


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-12-03 02:51 UTC

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