rpc: stop accepting HTTP RPC before shutdown #35184

pull ArtSabintsev wants to merge 1 commits into bitcoin:master from ArtSabintsev:codex/rpc-shutdown-before-mining changing 3 files +53 −12
  1. ArtSabintsev commented at 6:01 PM on April 30, 2026: none

    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 8
    • build/bin/test_bitcoin -t rpc_tests
    • test/functional/mining_getblocktemplate_longpoll.py --configfile build/test/config.ini
  2. DrahtBot added the label RPC/REST/ZMQ on Apr 30, 2026
  3. DrahtBot commented at 6:01 PM on April 30, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. ArtSabintsev force-pushed on Apr 30, 2026
  5. ArtSabintsev force-pushed on Apr 30, 2026
  6. ArtSabintsev force-pushed on Apr 30, 2026
  7. ArtSabintsev force-pushed on Apr 30, 2026
  8. ArtSabintsev marked this as ready for review on Apr 30, 2026
  9. sedited commented at 9:42 PM on April 30, 2026: contributor

    Did you use an LLM to write this? Can you rewrite the pull request description in your own words? I find your current description hard to follow. The testing instructions also don't really tell me anything.

  10. ArtSabintsev commented at 1:11 AM on May 1, 2026: none

    Did you use an LLM to write this? Can you rewrite the pull request description in your own words? I find your current description hard to follow. The testing instructions also don't really tell me anything.

    hey!

    Yup, used an LLM. Just fixed it up.

    Let me know if that makes more sense.

  11. furszy commented at 1:56 AM on May 1, 2026: member

    That can hit the existing CHECK_NONFATAL(block_template) assertion.

    CHECK_NONFATAL throws an exception, which gets caught by the RPC handler and returned to the user. The reported error message might not be the best, and could be improved, but it shouldn't abort the program.

    Also, the scenario you are describing should still be possible even with your modifications. It should just require a sleep time after the interruption check you added.

    That said, a single RpcInterruptionPoint() call early in JSONRPCExec seems good to have regardless.

  12. ArtSabintsev commented at 2:00 AM on May 1, 2026: none

    Thanks for following up @furszy

    Did you need me to update the PR description given your callout, or is anything else needed from me on this one?

  13. furszy commented at 2:12 AM on May 1, 2026: member

    Did you need me to update the PR description given your callout, or is anything else needed from me on this one?

    Having accurate information in the PR description helps for sure.

    If you prefer to keep the introduced RpcRequestInterruptionPoint() instead of using RpcInterruptionPoint(), it would be good to explain the reasoning for it. Also, the interruption function should be called only once early in the function, not in both conditional paths. And it would also be nice to know why the InterruptRPC() call was moved.

  14. rpc: stop accepting HTTP RPC before shutdown 353b6c6a95
  15. ArtSabintsev force-pushed on May 1, 2026
  16. ArtSabintsev commented at 2:31 AM on May 1, 2026: none

    Thanks, updated.

    • I dropped the new RpcRequestInterruptionPoint() helper and now call the existing RpcInterruptionPoint() once early in JSONRPCExec(), before dispatching the command.
    • I also updated the PR description to narrow the claim to this queued-shutdown path, changed Fixes [#34262](/bitcoin-bitcoin/34262/) to Refs [#34262](/bitcoin-bitcoin/34262/), and clarified that CHECK_NONFATAL returns through the RPC error path rather than aborting the process.
    • I kept the InterruptRPC() move and added the reasoning to the description: RPC should be marked interrupted before the mining longpoll waiters are woken.
  17. sedited commented at 5:39 AM on May 1, 2026: contributor

    I feel like we are just prompting the author's LLM here. That is probably not the best way to spend review time. The testing section in the description still says nothing about the actual issue. If you want to contribute to Bitcoin Core, please start with reviewing some pull requests yourself.

  18. sedited closed this on May 1, 2026


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-05-03 21:12 UTC

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