rpc: handle createNewBlock() returning nullptr during shutdown #36047

pull chriszeng1010 wants to merge 1 commits into bitcoin:master from chriszeng1010:gbt-shutdown-error changing 2 files +40 −4
  1. chriszeng1010 commented at 7:20 PM on August 20, 2026: none

    Problem

    createNewBlock() returns nullptr only when the node is shutting down (WaitTipChanged returns nullopt on interrupt and nothing else). The mining RPCs wrapped the result in CHECK_NONFATAL, reporting an expected shutdown condition as "Internal bug detected".

    Fix

    getblocktemplate and generateblock now throw "Shutting down" (RPC_CLIENT_NOT_CONNECTED), matching how getblocktemplate's longpoll path already reports the same condition. generateBlocks stops mining and returns the blocks found so far, matching its existing interrupt handling.

    Testing

    Add regression coverage: a longpoll getblocktemplate interrupted by shutdown must error with "Shutting down". Without the fix this raced ~50/50 between the correct error and the internal-bug error, because the IsRPCRunning() check runs before RPC is disabled during shutdown.

    Fixes #34262

  2. DrahtBot added the label RPC/REST/ZMQ on Aug 20, 2026
  3. DrahtBot commented at 7:20 PM on August 20, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/36047.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #35675 (mining: add block template manager by ismaelsadeeq)
    • #32468 (rpc: generateblock to allow multiple outputs by polespinasa)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. chriszeng1010 force-pushed on Aug 20, 2026
  5. rpc: handle createNewBlock() returning nullptr during shutdown
    getblocktemplate and generateblock now throw "Shutting down"
    (RPC_CLIENT_NOT_CONNECTED), matching how getblocktemplate's longpoll
    path already reports the same condition.
    b1fa37ea86
  6. chriszeng1010 force-pushed on Aug 20, 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-09-09 07:56 UTC