Repository navigation
Conversation
|
Please rebase onto the oldest commit this applies to rather than the |
An interrupted import may return from ImportBlocks without activating genesis. The init thread's wait for genesis is only woken by blockTip, which never fires in that case, so a shutdown request arriving during -reindex can leave startup blocked forever. Notify m_tip_block_cv after the import so the wait can observe the shutdown request. Adapted from bitcoin#35652.
2rdzy
force-pushed
the
fix-reindex-init-deadlock
branch
from
October 12, 2026 21:15
cb36ddc to
c1afd1c
Compare
Author
|
Rebased onto |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Backport of bitcoin#35652 ("init: fix reindex deadlock by waking cv after interrupt"). If shutdown is requested during
-reindexwhile the init thread is waiting for genesis, the node never exits. Theinitloadthread now wakes that wait after the import returns.Based on
v29.4(3fc0865). TheUpdateIBDStatusline that followsImportBlockson29.x-knotscomes from the lockless IBD backport and is not part of this change.Problem
All line numbers are at
v29.4.src/init.cpp:1879-1882: the init thread waits onm_tip_block_cvforTipBlock() || ShutdownRequested(node).src/node/blockstorage.cpp:1224-1226: afterLoadExternalBlockFile,ImportBlocksreturns early whenm_interruptis set, beforeActivateBestChain. NoblockTipfires, so genesis is never activated.node.shutdown_request(src/init.cpp:214-218). The SIGTERM handler (src/init.cpp:410-415) callsg_shutdowndirectly and does not go throughshutdown_request.Reproduction
feature_init.pychange from this PR (a-reindexstart, terminated afterReindexing block file blk00000.dat).timeout 100 python3 build/test/functional/feature_init.py.Test-only delay (not part of this PR)
Before
The test hit the 100 s
timeout(rc=124).bitcoindwas still running, with noShutdown: In progresslogged after the interrupt.Change
src/init.cpp: same hunk as Core;kernel_notificationsis already in scope.test/functional/feature_init.py: adds the-reindexstart from Core's test, run without the index args.assert_equal(0, node.process.wait())on every SIGTERM. That assertion comes from test: Check that interrupt results in EXIT_SUCCESS bitcoin/bitcoin#34241 (the test for init: Return EXIT_SUCCESS on interrupt bitcoin/bitcoin#34224, carried here asfix_init_int_ec-27), not from init: fix reindex deadlock by waking cv after interrupt bitcoin/bitcoin#35652, and fails onv29.4because an interrupted startup still exits 1 there.After
Same repro with the delay:
The test passes in 14 s.
Test results
Tested at
v29.4(3fc0865), with and without this change. CMake Release build: wallet, GUI, GUI tests and unit tests on; BDB off.ctest: 138/138 passed, before and after.--extended(324 tests): 253 passed, 65 skipped, 6 failed, before and after.feature_init.py,feature_dbcrash.py,feature_pruning.pyandfeature_index_prune.pypassed.wallet_groups.py --descriptors,feature_assumevalid.py,p2p_invalid_messages.py,rpc_createmultisig.py,wallet_miniscript.py --descriptorsandp2p_blockfilters.py. Run on their own, all 6 pass, with and without this change.Skips:
interface_usdt_*: USDT tracepoints not built.interface_zmq.py: zmq not enabled.feature_bind_port_*: need routable addresses 1.1.1.1 and 2.2.2.2.Caveats
stopand GUI shutdown, which go throughshutdown_requestand already notify.