New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shutdown: fix crash on shutdown with reindex-chainstate #12349
Conversation
Tests need update (test_bitcoin: coins.cpp:205: bool CCoinsViewCache::Flush(): Assertion `cachedCoinsUsage == 0' failed.) |
@TheBlueMatt pointed out that this shouldn't be new for 0.16, and I've now reproduced with 0.15.1. So, this probably shouldn't be an 0.16 blocker. |
I ran into this a few times during testing, which was somewhat surprising so maybe it is somehow easier to hit now? Not sure why that would be...still, worth fixing if there's an easy fix for 0.16 (eaiser fix is probably to make the ActivateBestChain if (ShutdownRequested()) check a if (ShutdownRequested() && chainActive.Tip() != nullptr) check). |
I prefer the fix in #12367 as much simpler. |
Closing for now |
dd2de47 Fix fast-shutdown crash if genesis block was not loaded (Matt Corallo) 1c9394a Fix fast-shutdown hang on ThreadImport+GenesisWait (Matt Corallo) Pull request description: The second commit is a much simpler alternative fix for the issue fixed in #12349. To test I made ShutdownRequested() always StartShutdown() after a certain number of calls, which turned up one other hang, fixed in the first commit. Tree-SHA512: 86bde6ac4b8b4e2cb99fff87dafeed02c0d9514acee6d94455637fb2da9ffc274b5ad31b0a6b9f5bd7b700ae35395f28ddb14ffc65ddda3619aa28df28a5607d
Without this change, I still get a segfault from bitcoind master (commit c997f88) reliably. To reproduce:
|
9f714e5
to
7b4d89f
Compare
Credit @eklitzke for reproducing.
7b4d89f
to
ceaefdd
Compare
Thanks for helping to reproduce, eklitzke! Indeed I managed to force this with this patch: --- a/src/init.cpp
+++ b/src/init.cpp
@@ -1520,6 +1520,7 @@ bool AppInitMain()
break;
}
}
+ fRequestShutdown = true;
if (!is_coinsview_empty) {
uiInterface.InitMessage(_("Verifying blocks...")); And running with:
I pushed a simple change that I think is obviously safe. I believe @TheBlueMatt would prefer a more elegant fix, but imo this is a reasonable option for the 0.16 branch. I defer to @wumpus on backporting. Note that at first glance it may make more sense to add the checks in init.cpp around the FlushStateToDisk()s, but the first is called without cs_main and I avoided messing with locks for the sake of simplicity. |
@TheBlueMatt, in IRC you wrote "we could revert to the initial suggestion of #12349 and just short-circuit flushing, but I really hate that" https://botbot.me/freenode/bitcoin-core-dev/msg/96765327/ Could you explain more? I haven't looked in detail, but at first glance this looks like a simple, obvious fix that doesn't rely on action at a distance like the one in #12367. |
You're deferring to the wrong wumpus! |
utACK We absolutely should have tests for this! it's a bit silly to merge a fix for something (#12367) then need another fix for the same thing, within the same rc phase. |
@laanwj Yea, this is a mess :( As a small data point, though, we believed this to be qt only and couldn't hit it with rc3. It was @eklitzke's bitcoind backtrace that made it easy to reproduce. I just tested with current master and can confirm that the bug and fix are still valid. Any suggestions for testing? Only thing I can think of is an rpc test that runs bitcoind with something like -stopafterblockimport, but that'd only be testing a really specific code path. |
Tested ACK ceaefdd. Can't reproduce the crash with this change. |
utACK ceaefdd
@TheBlueMatt's suggestion was pretty good
(but not in this PR, obviously) |
ceaefdd fix possible shutdown assertion with -reindex-shutdown (Cory Fields) Pull request description: Fixes the assertion error reported here: #12349 (comment) Tree-SHA512: db8e2a275f92a99df7f17852d00eba6df996e412aa3ed3853a9ea0a8cb9800760677532efd52f92abbf2cdcc4210957a87a5f919ac998d46c205365a7a7dffca
Credit @eklitzke for reproducing. Github-Pull: bitcoin#12349 Rebased-From: ceaefdd Tree-SHA512: bdc614d3c3fba23147be9528c581e25bbf1f0c359b525b4a05472ab42484724a8b34c8b3ed151f3ff23e48235e972950f9daa155d9ca3c4a9de6d61bf0591b4b Conflicts: src/validation.cpp
Summary: ceaefdd fix possible shutdown assertion with -reindex-shutdown (Cory Fields) Pull request description: Fixes the assertion error reported here: bitcoin/bitcoin#12349 (comment) Tree-SHA512: db8e2a275f92a99df7f17852d00eba6df996e412aa3ed3853a9ea0a8cb9800760677532efd52f92abbf2cdcc4210957a87a5f919ac998d46c205365a7a7dffca Backport of Core PR 12349 https://github.com/bitcoin/bitcoin/pull/12349/files Discovered while working on PR 12367 (D2906) Depends on D2906 Test Plan: `make check` On master, apply this patch: ``` diff --git a/src/init.cpp b/src/init.cpp index 56520fe..8d7371d 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -2139,6 +2139,7 @@ bool AppInitMain(Config &config, break; } } + fRequestShutdown = true; if (!fReindex && !fReindexChainState) { uiInterface.InitMessage(_("Verifying blocks...")); ``` Then run: `gdb --args ./src/bitcoind -connect=0 -testnet -reindex-chainstate` A crash should be encountered. Apply the same patch above on this diff and run the same command above. GDB should report a successful program exit. Reviewers: deadalnix, Fabien, #bitcoin_abc Reviewed By: Fabien, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D2907
Summary: ceaefdd fix possible shutdown assertion with -reindex-shutdown (Cory Fields) Pull request description: Fixes the assertion error reported here: bitcoin/bitcoin#12349 (comment) Tree-SHA512: db8e2a275f92a99df7f17852d00eba6df996e412aa3ed3853a9ea0a8cb9800760677532efd52f92abbf2cdcc4210957a87a5f919ac998d46c205365a7a7dffca Backport of Core PR 12349 https://github.com/bitcoin/bitcoin/pull/12349/files Discovered while working on PR 12367 (D2906) Depends on D2906 Test Plan: `make check` On master, apply this patch: ``` diff --git a/src/init.cpp b/src/init.cpp index 56520fe..8d7371d 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -2139,6 +2139,7 @@ bool AppInitMain(Config &config, break; } } + fRequestShutdown = true; if (!fReindex && !fReindexChainState) { uiInterface.InitMessage(_("Verifying blocks...")); ``` Then run: `gdb --args ./src/bitcoind -connect=0 -testnet -reindex-chainstate` A crash should be encountered. Apply the same patch above on this diff and run the same command above. GDB should report a successful program exit. Reviewers: deadalnix, Fabien, #bitcoin_abc Reviewed By: Fabien, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D2907
dd2de47 Fix fast-shutdown crash if genesis block was not loaded (Matt Corallo) 1c9394a Fix fast-shutdown hang on ThreadImport+GenesisWait (Matt Corallo) Pull request description: The second commit is a much simpler alternative fix for the issue fixed in bitcoin#12349. To test I made ShutdownRequested() always StartShutdown() after a certain number of calls, which turned up one other hang, fixed in the first commit. Tree-SHA512: 86bde6ac4b8b4e2cb99fff87dafeed02c0d9514acee6d94455637fb2da9ffc274b5ad31b0a6b9f5bd7b700ae35395f28ddb14ffc65ddda3619aa28df28a5607d
…instate ceaefdd fix possible shutdown assertion with -reindex-shutdown (Cory Fields) Pull request description: Fixes the assertion error reported here: bitcoin#12349 (comment) Tree-SHA512: db8e2a275f92a99df7f17852d00eba6df996e412aa3ed3853a9ea0a8cb9800760677532efd52f92abbf2cdcc4210957a87a5f919ac998d46c205365a7a7dffca
dd2de47 Fix fast-shutdown crash if genesis block was not loaded (Matt Corallo) 1c9394a Fix fast-shutdown hang on ThreadImport+GenesisWait (Matt Corallo) Pull request description: The second commit is a much simpler alternative fix for the issue fixed in bitcoin#12349. To test I made ShutdownRequested() always StartShutdown() after a certain number of calls, which turned up one other hang, fixed in the first commit. Tree-SHA512: 86bde6ac4b8b4e2cb99fff87dafeed02c0d9514acee6d94455637fb2da9ffc274b5ad31b0a6b9f5bd7b700ae35395f28ddb14ffc65ddda3619aa28df28a5607d
…instate ceaefdd fix possible shutdown assertion with -reindex-shutdown (Cory Fields) Pull request description: Fixes the assertion error reported here: bitcoin#12349 (comment) Tree-SHA512: db8e2a275f92a99df7f17852d00eba6df996e412aa3ed3853a9ea0a8cb9800760677532efd52f92abbf2cdcc4210957a87a5f919ac998d46c205365a7a7dffca
dd2de47 Fix fast-shutdown crash if genesis block was not loaded (Matt Corallo) 1c9394a Fix fast-shutdown hang on ThreadImport+GenesisWait (Matt Corallo) Pull request description: The second commit is a much simpler alternative fix for the issue fixed in bitcoin#12349. To test I made ShutdownRequested() always StartShutdown() after a certain number of calls, which turned up one other hang, fixed in the first commit. Tree-SHA512: 86bde6ac4b8b4e2cb99fff87dafeed02c0d9514acee6d94455637fb2da9ffc274b5ad31b0a6b9f5bd7b700ae35395f28ddb14ffc65ddda3619aa28df28a5607d
…instate ceaefdd fix possible shutdown assertion with -reindex-shutdown (Cory Fields) Pull request description: Fixes the assertion error reported here: bitcoin#12349 (comment) Tree-SHA512: db8e2a275f92a99df7f17852d00eba6df996e412aa3ed3853a9ea0a8cb9800760677532efd52f92abbf2cdcc4210957a87a5f919ac998d46c205365a7a7dffca
Fixes the assertion error reported here: #12349 (comment)