init: Fix Ctrl-C shutdown hangs during wait calls #33511

pull ryanofsky wants to merge 2 commits into bitcoin:master from ryanofsky:pr/sigwait changing 3 files +54 −9
  1. ryanofsky commented at 7:14 pm on September 30, 2025: contributor

    Signal m_tip_block_cv when Ctrl-C is pressed or SIGTERM is received, the same way it is currently signaled when the stop RPC is called. This lets RPC calls like waitforblockheight and IPC calls like waitTipChanged be interrupted, instead of waiting for their original timeouts and delaying shutdown.

    This issue was reported by plebhash in #33463. These hangs have been present since #30409. A similar bug was also fixed previously in Qt in #18452 and this PR simplifies that fix.

  2. test: Test SIGTERM handling during waitforblockheight call
    Currently when CTRL-C is pressed and there is an active `waitforblockheight`,
    or `waitforblock`, or `waitfornewblock` RPC call, or a mining interface
    `waitTipChanged` IPC call with a long timeout, the node will not shut down
    right away, and will wait for the timeout to be reached before exiting.
    
    This behavior is not ideal and only happens when the node is stopped with
    CTRL-C or SIGTERM. When the node is stopped with `bitcoin-cli stop`, the wait
    calls are interrupted and the node does shut down right away.
    
    The next commit improves node behavior. This commit just adds test coverage to
    simplify the next commit and clarify the change in behavior there.
    6a29f79006
  3. DrahtBot commented at 7:15 pm on September 30, 2025: contributor

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

    Code Coverage & Benchmarks

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

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK Sjors, TheCharlatan
    Concept ACK enirox001

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #29770 (index: Check all necessary block data is available before starting to sync by fjahr)

    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.

  4. ryanofsky commented at 3:12 pm on October 1, 2025: contributor

    I’m confused by windows CI failures: 1 2

    They seem to show py -3 test_runner.py being called, and this just with failing with no output after around 10 minutes, with CI reporting Process completed with exit code -1073741510. where -1073741510 is 0xc000013a or STATUS_CONTROL_C_EXIT. So it seems like sending ctrl-c to the node might be killing the whole test?

    EDIT: Turns out this is expected, the test needs to start the node with creationflags=subprocess.CREATE_NEW_PROCESS_GROUP on windows, otherwise ctrl-c does kill all processes.

  5. init: Signal m_tip_block_cv on Ctrl-C
    Signal m_tip_block_cv when Ctrl-C is pressed or SIGTERM is received, the same
    way it is currently signalled when the `stop` RPC is called. This lets RPC
    calls like `waitforblockheight` and IPC calls like `waitTipChanged` be
    interrupted, instead of waiting for their original timeouts and delaying
    shutdown.
    
    Historical notes:
    
    - The behavior where `stop` RPC signals `m_tip_block_cv`, but CTRL-C does not,
      has been around since the condition variable was introduced in #30409
      (7eccdaf16081d6f624c4dc21df75b0474e049d2b).
    - The signaling was later moved without changing behavior in #30967
      (5ca28ef28bcca1775ff49921fc2528d9439b71ab). This commit moves it again to
      the Interrupt() function, which is probably the place it should have been
      added initially, so it works for Ctrl-C shutdowns as well as `stop`
      shutdowns.
    - A Qt shutdown bug calling wait methods was fixed previously in #18452
      (da73f1513a637a9f347b64de66564d6cdb2541f8), and this change updates that
      fix to avoid the hang happening again in Qt.
    c25a5e670b
  6. ryanofsky force-pushed on Oct 1, 2025
  7. ryanofsky commented at 5:36 pm on October 1, 2025: contributor
    Updated 4ee8e2248e54a33f0a3a2e808d46a7b0b8ea7bc3 -> 68cad90dace40f7a015ca4ff81b878fc8fdc1dd5 (pr/sigwait.1 -> pr/sigwait.2, compare) to fix CI failures, also added more documentation and explanation in commit description
  8. ryanofsky renamed this:
    init: Signal m_tip_block_cv on Ctrl-C
    init: Fix Ctrl-C shutdown hangs during wait calls
    on Oct 1, 2025
  9. TheCharlatan approved
  10. TheCharlatan commented at 8:55 pm on October 1, 2025: contributor

    ACK 68cad90dace40f7a015ca4ff81b878fc8fdc1dd5

    This should be backported in my opinion.

  11. Sjors commented at 8:45 am on October 2, 2025: member
    ACK 68cad90dace40f7a015ca4ff81b878fc8fdc1dd5 (see below)
  12. Sjors commented at 9:57 am on October 2, 2025: member

    Mmm, the GUI experience is less great (testnet4, ctrl + c from the terminal where I launched it):

    This seems to stay stuck.

    Doesn’t happen on the first commit, so might be a regression.

  13. ryanofsky commented at 10:19 am on October 2, 2025: contributor

    Mmm, the GUI experience is less great (testnet4, ctrl + c from the terminal where I launched it): […] Doesn’t happen on the first commit, so might be a regression.

    Oh, thanks for testing. That does sound like a regression. Will mark as draft until this is debugged

  14. ryanofsky marked this as a draft on Oct 2, 2025
  15. fanquake commented at 3:30 pm on October 2, 2025: member

    This should be backported in my opinion.

    Not going to block 30.0 if it’s not ready, but marked for backport.

  16. fanquake added the label Needs backport (30.x) on Oct 2, 2025
  17. luke-jr referenced this in commit e4713ff8f9 on Oct 2, 2025
  18. luke-jr referenced this in commit 663bc960f5 on Oct 2, 2025
  19. ryanofsky force-pushed on Oct 3, 2025
  20. ryanofsky commented at 8:46 pm on October 3, 2025: contributor
    Updated 68cad90dace40f7a015ca4ff81b878fc8fdc1dd5 -> c25a5e670b27d3b6eb958ce437dbe89678bd1511 (pr/sigwait.2 -> pr/sigwait.3, compare) fixing regression in previous version that caused Qt shutdown to hang during wait calls from the GUI console
  21. ryanofsky marked this as ready for review on Oct 3, 2025
  22. Sjors commented at 9:08 am on October 4, 2025: member

    tACK c25a5e670b27d3b6eb958ce437dbe89678bd1511

    It’s also a nice simplification.

  23. DrahtBot requested review from TheCharlatan on Oct 4, 2025
  24. TheCharlatan approved
  25. TheCharlatan commented at 9:47 am on October 5, 2025: contributor
    Thanks for the fix, makes sense to call Interrupt earlier in the shutdown sequence. ACK c25a5e670b27d3b6eb958ce437dbe89678bd1511
  26. fanquake added this to the milestone 30.1 on Oct 8, 2025
  27. enirox001 commented at 9:08 pm on October 11, 2025: contributor

    Concept ACK c25a5e6

    Replicated the issue; fix works. Good refactor in init and interfaces for interrupt support.

    • regtest: RPC interrupts immediately on shutdown signal.
    • testnet: RPC does not interrupt and waits for timeout.

    Tested on Linux with Ctrl+C to trigger the signal interruption. Please clarify testnet behavior.

  28. TheCharlatan commented at 12:07 pm on October 31, 2025: contributor
    rfm?

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: 2025-11-01 00:13 UTC

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