Skip to content

Conversation

@sedited
Copy link
Contributor

@sedited sedited commented Jan 7, 2026

Reported by dergoegge on irc.

An interrupt does not create a failure exit code during normal operation. This should also be the case when interrupt is triggered during initialization. However a failure exit code is currently returned if an interrupt occurs during init. Fix this by making AppInitMain return true instead of false on interrupt, which further up the call stack currently sets the EXIT_FAILURE code. Also add a check for the interrupt condition during GUI startup. Returning EXIT_SUCCESS seems to be the usual behaviour for daemons, see the discussion on IRC for this: https://www.erisian.com.au/bitcoin-core-dev/log-2026-01-08.html#l-146 .

Best reviewed with --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 7, 2026

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/34224.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK maflcko, janb84, dergoegge
Concept ACK bensig

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

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.

@bensig
Copy link
Contributor

bensig commented Jan 7, 2026

Concept ACK 3dbbac0

Copy link
Member

@dergoegge dergoegge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK 3dbbac0

@maflcko
Copy link
Member

maflcko commented Jan 8, 2026

I don't think this works. At least locally, I am still seeing 1 when I ^C later. I used a diff to make this easier to test:

diff --git a/src/init.cpp b/src/init.cpp
index f2af858eb4..b6e903c497 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1828,2 +1828,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
 
+    std::cout << "a\n";
+    UninterruptibleSleep(1s);
+    std::cout << "b\n";
+
     // As LoadBlockIndex can take several minutes, it's possible the user

So it now works fine when pressing ^C before b is printed, but not after:

$ ./bld-cmake/bin/bitcoind -noprinttoconsole=1 
a
^Cb
$ echo $?
0  # works correctly
$ ./bld-cmake/bin/bitcoind -noprinttoconsole=1 
a
b
^C $?
1  # wrong exit code?

An interrupt does not create a failure exit code during normal
operation. This should also be the case when interrupt is triggered
during initialization. However a failure exit code is currently returned
if an interrupt occurs during init. Fix this by making `AppInitMain` return
true instead of false, which further up the call stack sets the
`EXIT_FAILURE` code. Also add a check for the interrupt condition during
GUI startup.
@sedited sedited force-pushed the init_interrupt_zero branch from 3dbbac0 to 997e7b4 Compare January 8, 2026 19:36
@sedited
Copy link
Contributor Author

sedited commented Jan 8, 2026

Updated 3dbbac0 -> 997e7b4 (init_interrupt_zero_0 -> init_interrupt_zero_1, compare)

  • Addressed @maflcko's comment, added previously missed case for returning after a shutdown is detected. These are kind of difficult to find exhaustively, but I did reproduce the missing case too, and this seems to fix it for me.

@maflcko
Copy link
Member

maflcko commented Jan 8, 2026

review ACK 997e7b4 🔺

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: review ACK 997e7b4d7cf7c4622938798423447375383184c0 🔺
7kAK1PhE4TRlfj2lMDMYSH0Tv1kSe6YM9Cw6AfqLtacMJiC4gTxuBXuEbmNxNjE5AQEbnvhFG/hFZ1oTv9tJAw==

@DrahtBot DrahtBot requested a review from dergoegge January 8, 2026 19:56
Copy link
Contributor

@janb84 janb84 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 997e7b4

PR fixes exit code on SIGINT while being in init.

While I was first under the impression that the exit code should be 130 (as per Advanced Bash-Scripting Guide:) because of SIGINT, this is not the case. SIGINT is correctly handled by the application ending in a clean shutdown so it should be 0 (which is the case after this PR)

e.g. killing a bitcoin node with SIGKILL results in a 137

Details
2026-01-08T20:26:49Z dnsseed thread exit
Killed: 9                  ./bitcoind --regtest

[nix-shell:~/Projects/bitcoin/build_dev_mode/bin]$ echo $?
137

Copy link
Member

@dergoegge dergoegge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 997e7b4

@maflcko
Copy link
Member

maflcko commented Jan 13, 2026

rfm?

@glozow glozow merged commit 377c6db into bitcoin:master Jan 13, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants