Potential deadlocks #1801

issue laanwj opened this issue on September 8, 2012
  1. laanwj commented at 11:22 AM on September 8, 2012: member

    I performed a bit of hand-rolled static analysis on the Bitcoin source to check for potential deadlocks, by examining partial lock orders (like DEBUG_LOCKORDER but more thorough). I found a few, which I checked manually.

    This list is not comprehensive, as indirect calls (functions pointers, virtual functions, such as in the RPC dispatcher) are currently ignored by my static checker.

    These cases are the exceptions. The cases under "counterexample" are the "normal" order, or at least the most common one.

    Case 4 involves TRY_LOCKs, so it is probably OK.

    1.

    SendMessages LOCKs cs_inventory lock on a node → CWallet::GetTransaction LOCKs the cs_wallet lock.

    Counterexample: CWallet::ResendWalletTransactions LOCKs cs_wallet lock → CWallet::RelayWalletTransactionRelayMessageRelayInventoryCNode::PushInventory which LOCKs the cs_inventory lock

    2.

    CTxMemPool::accept(CTxDB&, CTransaction&, bool, bool*) LOCKs local static lock for rate-limit → CWallet::GetDebit(CTransaction const&) constCWallet::GetDebit(CTxIn const&) const LOCKs CWallet lock

    Counterexample: CWallet::CommitTransaction(CWalletTx&, CReserveKey&) LOCKs CWallet lock → CMerkleTx::AcceptToMemoryPool()CTxMemPool::accept(CTxDB&, CTransaction&, bool, bool*) LOCKs local static lock for rate-limit

    3.

    CWalletTx::AcceptWalletTransaction(CTxDB&, bool) LOCKs CTxMemPool:cs → CTxMemPool::accept(CTxDB&, CTransaction&, bool, bool*)CWallet::GetDebit(CTransaction const&)CWallet::GetDebit(CTxIn const&) LOCKs CWallet:cs_wallet

    CreateNewBlock(CReserveKey&) LOCKs CTxMemPool:cs → CBlock::ConnectBlock(CTxDB&, CBlockIndex*, bool)CWallet::AddToWalletIfInvolvingMe(CTransaction const&, CBlock const*, bool, bool) LOCKs CWallet:cs_wallet

    Counterexample: CWallet::CommitTransaction(CWalletTx&, CReserveKey&) LOCKs CWallet:cs_wallet → CMerkleTx::AcceptToMemoryPool()CTransaction::ClientConnectInputs() LOCKs CTxMemPool:cs

    4.

    ThreadSocketHandler2(void*) LOCKs cs_vNodes, then TRYLOCKs CNode:cs_vSend (when disconnecting nodes)

    Counterexample: ThreadMessageHandler2(void*) TRYLOCKs CNode:cs_vSend → SendMessages(CNode*, bool) LOCKs cs_vNodes (for address refresh broadcast)

  2. Diapolo commented at 10:29 AM on October 28, 2013: none

    @laanwj @sipa Is this still one of our problems? I know there were some changes recently.

  3. laanwj closed this on Jan 10, 2014

  4. KolbyML referenced this in commit 9c06e5d7ce on Dec 5, 2020
  5. KolbyML referenced this in commit ad15bce2f5 on Dec 5, 2020
  6. DrahtBot locked this on Sep 8, 2021
Contributors
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-13 15:16 UTC

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