Refs #34262
getblocktemplate asks Bitcoin Core to build a candidate block for mining.
The problem is that an RPC request can be accepted before shutdown starts, but sit in the HTTP RPC queue and only begin running after shutdown has already started.
During shutdown, Bitcoin Core wakes up mining code that is waiting. So if the queued request is getblocktemplate, it can continue into block template creation after RPC shutdown has started. That can hit the existing CHECK_NONFATAL(block_template) check and return a less helpful internal RPC error instead of the normal shutdown RPC error.
This PR handles that queued-shutdown path by checking for RPC interruption once, early in JSONRPCExec(), before command execution starts. It also interrupts RPC earlier in shutdown, before waking mining waiters.
This keeps the existing CHECK_NONFATAL in getblocktemplate. The check still catches unexpected internal bugs, while this shutdown case should be handled before the command starts running.
To test this, the new regression test fills both RPC worker threads with longpolling getblocktemplate calls, then queues one more getblocktemplate request behind them. It then shuts down the node and checks that the queued request returns the normal shutdown RPC error.
Testing:
cmake --build build --target test_bitcoin -j 8build/bin/test_bitcoin -t rpc_teststest/functional/mining_getblocktemplate_longpoll.py --configfile build/test/config.ini