Skip to content

Commit 79313d2

Browse files
committed
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
2 parents fe53d5f + a8b5d20 commit 79313d2

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/init.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,9 @@ bool AppInitMain()
14251425
pcoinsTip.reset();
14261426
pcoinsdbview.reset();
14271427
pcoinscatcher.reset();
1428+
// new CBlockTreeDB tries to delete the existing file, which
1429+
// fails if it's still open from the previous loop. Close it first:
1430+
pblocktree.reset();
14281431
pblocktree.reset(new CBlockTreeDB(nBlockTreeDBCache, false, fReset));
14291432

14301433
if (fReset) {

0 commit comments

Comments
 (0)