aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2018-02-12 10:11:28 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2018-02-12 10:11:37 +0100
commit79313d2e2040451ef98a7a921c53f7736208c934 (patch)
treefd0db0a5107520d3c6158117a82ca4435d53f832
parentfe53d5f3636aed064823bc220d828c7ff08d1d52 (diff)
parenta8b5d20f4f171828b2bd70ab2405c42b1e452e5b (diff)
downloadbitcoin-79313d2e2040451ef98a7a921c53f7736208c934.tar.xz
Merge #12401: Reset pblocktree before deleting LevelDB file
a8b5d20 Reset pblocktree before deleting LevelDB file (Sjors Provoost) Pull request description: #11043 repaced: ``` delete pblocktree; pblocktree = new CBlockTreeDB(nBlockTreeDBCache, false, fReset); ``` With: ``` pblocktree.reset(new CBlockTreeDB(nBlockTreeDBCache, false, fReset)); ``` This is problematic because `new CBlockTreeDB` tries to delete the existing file, which will fail with `LOCK: already held by process` if it's still open. That's the case for QT. When QT finds a problem with the index it will ask the user if they want to reindex. At that point it has already opened `blocks/index`. It then runs this [while loop](https://github.com/bitcoin/bitcoin/blob/v0.16.0rc3/src/init.cpp#L1415) again with `fReset = 1`, resulting in the above error. This change makes that error go away, presumably because `reset()` without an argument closes the file. Tree-SHA512: fde8b546912f6773ac64da8476673cc270b125aa2d909212391d1a2001b35c8260a8772126b99dfd76b39faaa286feb7c43239185fe584bd4dc2bc04a64044ce
-rw-r--r--src/init.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 84398d978c..4ff875f9aa 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1425,6 +1425,9 @@ bool AppInitMain()
pcoinsTip.reset();
pcoinsdbview.reset();
pcoinscatcher.reset();
+ // new CBlockTreeDB tries to delete the existing file, which
+ // fails if it's still open from the previous loop. Close it first:
+ pblocktree.reset();
pblocktree.reset(new CBlockTreeDB(nBlockTreeDBCache, false, fReset));
if (fReset) {