Initial wallet loading takes locks in wrong order causing POTENTIAL DEADLOCK DETECTED #9772

issue morcos opened this issue on February 15, 2017
  1. morcos commented at 10:17 PM on February 15, 2017: member

    In init.cpp we call InitLoadWallet which eventually calls CWalletDB::LoadWallet which takes cs_wallet, in the course of loading the wallet it calls LoadToWallet which calls MarkConflicted which takes cs_main. This is the opposite order that these locks are taking in countless other places in the code (often in a LOCK2(cs_main, cs_wallet)). I don't think there is a risk of actual deadlock here because LoadWallet only gets called from init.cpp before network threads or rpc threads are functional. However since it causes an assertion failure with -DDEBUG_LOCKORDER it can make it difficult to do other lock order debugging.

    One work around is to just not have any transactions in the wallet which need to be marked conflicted.

    It may be the case that the proper lock order is actually wallet and then main, and the right fix is to actually fix all the other locks in the code, so I'm just noting the issue for now.

  2. fanquake added the label Wallet on Feb 16, 2017
  3. laanwj commented at 7:58 AM on February 16, 2017: member

    It may be the case that the proper lock order is actually wallet and then main, and the right fix is to actually fix all the other locks in the code, so I'm just noting the issue for now.

    Not ever holding them at the same time would be the ideal. Not quite a short-term solution to this issue, but it'd be a step in disentangling the wallets dependencies on the core.

  4. ryanofsky commented at 9:32 PM on December 14, 2017: member

    Can be closed. This was reported separately by luke and fixed in #11126.

  5. fanquake closed this on Dec 14, 2017

  6. MarcoFalke locked this on Sep 8, 2021
Labels

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-21 15:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me