Skip to content

Commit

Permalink
Fix potential deadlock in LoadWallet() (#2806)
Browse files Browse the repository at this point in the history
* Fix potential deadlock in LoadWallet()

```
POTENTIAL DEADLOCK DETECTED
Previous lock order was:
 (1) cs_main  wallet/wallet.cpp:3881
 (2) cs_wallet  wallet/wallet.cpp:3881
Current lock order is:
 (2) pwallet->cs_wallet  wallet/walletdb.cpp:589
 (1) cs_main  wallet/wallet.cpp:1252
```

* Add comment in CWallet::MarkConflicted re new cs_main lock in CWalletDB::LoadWallet()
  • Loading branch information
UdjinM6 committed Mar 25, 2019
1 parent 81eeff1 commit 162acc5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ bool CWallet::AbandonTransaction(const uint256& hashTx)

void CWallet::MarkConflicted(const uint256& hashBlock, const uint256& hashTx)
{
LOCK2(cs_main, cs_wallet);
LOCK2(cs_main, cs_wallet); // check "LOCK2(cs_main, pwallet->cs_wallet);" in CWalletDB::LoadWallet()

int conflictconfirms = 0;
if (mapBlockIndex.count(hashBlock)) {
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/walletdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
bool fNoncriticalErrors = false;
DBErrors result = DB_LOAD_OK;

LOCK(pwallet->cs_wallet);
LOCK2(cs_main, pwallet->cs_wallet);
try {
int nMinVersion = 0;
if (Read((std::string)"minversion", nMinVersion))
Expand Down

0 comments on commit 162acc5

Please sign in to comment.