lbrycrd/src/wallet
Wladimir J. van der Laan 7cc1bd3aae
Merge #13161: wallet: Reset BerkeleyDB handle after connection fails
b6f0b4d wallet: Improve logging when BerkeleyDB environment fails to close (Tim Ruffing)
264c643 wallet: Reset BerkeleyDB handle after connection fails (Tim Ruffing)

Pull request description:

  According to the BerkeleyDB docs, the DbEnv handle may not be accessed
  after close() has been called. This change ensures that we create a new
  handle after close() is called. This avoids a segfault when the first
  connection attempt fails and then a second connection attempt tries to
  call open() on the already closed DbEnv handle.

  Without the patch, bitcoindd reliably crashes in the second call to `set_lg_dir()` after `close()` if
  there is an issue with the database:
  ```
  2018-05-03T13:27:21Z Bitcoin Core version v0.16.99.0-a024a1841-dirty (debug build)
  [...]
  2018-05-03T13:27:21Z Using wallet directory /home/tim/.bitcoin
  2018-05-03T13:27:21Z init message: Verifying wallet(s)...
  2018-05-03T13:27:21Z Using BerkeleyDB version Berkeley DB 4.8.30: (April  9, 2010)
  2018-05-03T13:27:21Z Using wallet wallet.dat
  2018-05-03T13:27:21Z BerkeleyEnvironment::Open: LogDir=/home/tim/.bitcoin/database
  2018-05-03T13:27:21Z BerkeleyEnvironment::Open: Error -30974 opening database environment: DB_RUNRECOVERY: Fatal error, run database recovery
  2018-05-03T13:27:21Z Moved old /home/tim/.bitcoin/database to /home/tim/.bitcoin/database.1525354041.bak. Retrying.
  2018-05-03T13:27:21Z BerkeleyEnvironment::Open: LogDir=/home/tim/.bitcoin/database ErrorFile=/home/tim/.bitcoin/db.log
  [1]    14533 segmentation fault (core dumped)  ./src/bitcoind
  ```

  After the fix:
  ```
  2018-05-03T17:19:32Z Bitcoin Core version v0.16.99.0-cc09e3bd0-dirty (release build)
  [...]
  2018-05-03T17:19:32Z Using wallet directory /home/tim/.bitcoin
  2018-05-03T17:19:32Z init message: Verifying wallet(s)...
  2018-05-03T17:19:32Z Using BerkeleyDB version Berkeley DB 4.8.30: (April  9, 2010)
  2018-05-03T17:19:32Z Using wallet wallet.dat
  2018-05-03T17:19:32Z BerkeleyEnvironment::Open: LogDir=/home/tim/.bitcoin/database ErrorFile=/home/tim/.bitcoin/db.log
  2018-05-03T17:19:32Z scheduler thread start
  2018-05-03T17:19:32Z BerkeleyEnvironment::Open: Error -30974 opening database environment: DB_RUNRECOVERY: Fatal error, run database recovery
  2018-05-03T17:19:32Z Moved old /home/tim/.bitcoin/database to /home/tim/.bitcoin/database.1525367972.bak. Retrying.
  2018-05-03T17:19:32Z BerkeleyEnvironment::Open: LogDir=/home/tim/.bitcoin/database ErrorFile=/home/tim/.bitcoin/db.log
  2018-05-03T17:19:32Z Cache configuration:
  2018-05-03T17:19:32Z * Using 2.0MiB for block index database
  2018-05-03T17:19:32Z * Using 8.0MiB for chain state database
  2018-05-03T17:19:32Z * Using 440.0MiB for in-memory UTXO set (plus up to 286.1MiB of unused mempool space)
  2018-05-03T17:19:32Z init message: Loading block index..
  [...]
  ```

Tree-SHA512: b809b318e5014ec47d023dc3dc40826b9706bfb211fa08bc2d29f36971b96caa10ad48d9a3f96c03933be46fa4ff7e00e952ac77bfffb6563767fb08aa4f23d6
2018-05-14 15:06:48 +02:00
..
test wallet: Add AddWallet, RemoveWallet, GetWallet and GetWallets 2018-04-18 22:07:33 +01:00
coincontrol.h wallet: Make fee settings non-static members 2018-04-23 10:49:21 -04:00
coinselection.cpp Add missing newlines to LogPrint debug logging 2018-05-02 15:14:04 +02:00
coinselection.h Fix missing or inconsistent include guards 2018-03-22 16:23:04 +01:00
crypter.cpp Merge #11403: SegWit wallet support 2018-01-10 20:55:41 -10:00
crypter.h tests: Avoid test suite name collision in wallet crypto_tests 2018-04-06 16:29:14 +02:00
db.cpp wallet: Improve logging when BerkeleyDB environment fails to close 2018-05-09 15:23:16 +02:00
db.h scripted-diff: Rename wallet database classes 2018-04-07 11:48:27 -05:00
feebumper.cpp wallet: Make fee settings non-static members 2018-04-23 10:49:21 -04:00
feebumper.h feebumper: Use PreconditionChecks to determine bump eligibility 2018-01-29 18:31:33 -05:00
fees.cpp wallet: Make fee settings non-static members 2018-04-23 10:49:21 -04:00
fees.h wallet: Make fee settings non-static members 2018-04-23 10:49:21 -04:00
init.cpp Make gArgs aware of the arguments 2018-05-09 12:21:05 -04:00
rpcdump.cpp Make it clear which functions that are intended to be translation unit local 2018-05-03 21:47:40 +02:00
rpcwallet.cpp Add 'sethdseed' RPC to initialize or replace HD seed 2018-05-12 13:15:21 -04:00
rpcwallet.h Split signrawtransaction into wallet and non-wallet 2018-02-17 11:42:00 -05:00
wallet.cpp Merge #12560: [wallet] Upgrade path for non-HD wallets to HD 2018-05-14 11:17:29 +02:00
wallet.h Bump wallet version for pre split keypool 2018-05-12 13:15:21 -04:00
walletdb.cpp Make it clear which functions that are intended to be translation unit local 2018-05-03 21:47:40 +02:00
walletdb.h [wallet] [rpc] introduce 'label' API for wallet 2018-04-10 19:27:22 -04:00
walletutil.cpp Don't allow relative -walletdir paths 2018-01-18 15:09:27 -05:00
walletutil.h Fix missing or inconsistent include guards 2018-03-22 16:23:04 +01:00