You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
rpc: Assertion 'block_template' failed in getblocktemplate (during shutdown or startup) #34262
changed the title [-]rpc: Assertion `block_template' failed in `getblocktemplate` (during shutdown or startup)[/-][+]rpc: Assertion 'block_template' failed in `getblocktemplate` (during shutdown or startup)[/+]on Jan 12, 2026
I tried reproducing this locally by spamming getblocktemplate calls during startup and shutdown, but couldn't trigger the race condition (given the timing window).
Looking at the debug logs:
Shutdown case: "Shutdown in progress..." message appears right before the assertion failure
Startup case: Assertion fails while node is still initializing (network threads just starting)
Both show Assertion 'block_template' failed, which means createNewBlock() returned nullptr when the mining subsystem wasn't available.
The issue is that CHECK_NONFATAL assumes this should never happen, but nullptr is actually a valid return during these states. The fix is to replace the assertion with a proper null check and return an RPC error instead.
The pull requests in question were not just closed because they were using LLMs, but because they didn't fix the problem and the authors didn't understand the fixes they were applying. It would still be good to address this issue properly.
I'm able to reproduce the error by setting up a test node with a funded wallet and running getblocktemplate on the 1st thread with a longpoll ID on a second terminal to display result. And then, I ran Cli stop after sending funds on the first terminal triggers a 2nd thread to run the shut down process.
This happens on half of the attempts that I've tried. The other half exists normally with error -9 (Shut down)
Thread B notifies shutdown and wakes up Thread A running the following:
void Interrupt(NodeContext& node)
{
#if HAVE_SYSTEM
ShutdownNotify(*node.args);
#endif
// Wake any threads that may be waiting for the tip to change.
if (node.notifications) WITH_LOCK(node.notifications->m_tip_block_mutex, node.notifications->m_tip_block_cv.notify_all());
InterruptHTTPServer();
InterruptHTTPRPC();
InterruptRPC();
......
}
std::optional<BlockRef> maybe_tip{miner.waitTipChanged(hashWatchedChain, checktxtime)};
// Node is shutting down
if (!maybe_tip) break;
..........
if (!IsRPCRunning())
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Shutting down");
Mean while on Thread B its 3 lines away from InterruptRPC()
// wake up everyone here
if (node.notifications) WITH_LOCK(node.notifications->m_tip_block_mutex, node.notifications->m_tip_block_cv.notify_all());
InterruptHTTPServer();
InterruptHTTPRPC();
//interrupt here
InterruptRPC();
If B is faster and makes it in time, A shuts down correctly.
The startup failure path is the same as shutdown failure path triggered by the same condition chainman.m_interrupt || interrupt caused by the shutdown flag.
Activity
[-]rpc: Assertion `block_template' failed in `getblocktemplate` (during shutdown or startup)[/-][+]rpc: Assertion 'block_template' failed in `getblocktemplate` (during shutdown or startup)[/+]DevPatel-11 commentedon Jan 17, 2026
I'd like to work on this. Looking at the code now.
DevPatel-11 commentedon Jan 19, 2026
I tried reproducing this locally by spamming
getblocktemplatecalls during startup and shutdown, but couldn't trigger the race condition (given the timing window).Looking at the debug logs:
Both show
Assertion 'block_template' failed, which meanscreateNewBlock()returned nullptr when the mining subsystem wasn't available.The issue is that
CHECK_NONFATALassumes this should never happen, but nullptr is actually a valid return during these states. The fix is to replace the assertion with a proper null check and return an RPC error instead.I'll open a PR with the fix.
chriszeng1010 commentedon Aug 18, 2026
Looks like this issue is closed due to LLM usage. Should we still work on this?
sedited commentedon Aug 18, 2026
The pull requests in question were not just closed because they were using LLMs, but because they didn't fix the problem and the authors didn't understand the fixes they were applying. It would still be good to address this issue properly.
chriszeng1010 commentedon Aug 18, 2026
I'll take a crack at this.
chriszeng1010 commentedon Aug 18, 2026
I'm able to reproduce the error by setting up a test node with a funded wallet and running getblocktemplate on the 1st thread with a longpoll ID on a second terminal to display result. And then, I ran
Cli stopafter sending funds on the first terminal triggers a 2nd thread to run the shut down process.This happens on half of the attempts that I've tried. The other half exists normally with error -9 (Shut down)
$ ./build/bin/bitcoin-cli -regtest -datadir=/tmp/gbtrepro getblocktemplate '{"rules":["segwit"],"longpollid":"4d9ad53b6b0cdda5d3e2f46ca3065053068dc7095d713034d355f237a783457c4"}'
error code: -1
error message:
Internal bug detected: block_template
./rpc/mining.cpp:910 (getblocktemplate()::<lambda(const RPCMethod&, const JSONRPCRequest&)>)
Bitcoin Core v31.99.0-311847fffa21
Please report this issue here: https://github.com/bitcoin/bitcoin/issues
chriszeng1010 commentedon Aug 18, 2026
There's a race condition during shutdown.
Thread A sleeps here on condition after longpoll to call
getblocktemplateThread B notifies shutdown and wakes up Thread A running the following:
Thread A Wakes up, continues, and returns {}
And then it exits
Mean while on Thread B its 3 lines away from InterruptRPC()
If B is faster and makes it in time, A shuts down correctly.
Otherwise, A keeps going, hits here
And then end up in here and returns empty {}
And failing here
CHECK_NONFATAL(block_template);chriszeng1010 commentedon Aug 18, 2026
I will also check startup path.
chriszeng1010 commentedon Aug 20, 2026
The startup failure path is the same as shutdown failure path triggered by the same condition
chainman.m_interrupt || interruptcaused by the shutdown flag.rpc: handle createNewBlock() returning nullptr during shutdown
rpc: handle createNewBlock() returning nullptr during shutdown
chriszeng1010 commentedon Aug 30, 2026
Can i ask the reviewers to take a look at the PR? Thanks.
maflcko commentedon Aug 31, 2026
@chriszeng1010 Instead of asking for review on what is basically a small style cleanup, you can help with review of the other ~400 open pull requests.