Fix AddAddress cs_mapaddresses/db transaction deadlock #500

pull gavinandresen wants to merge 1 commits into bitcoin:master from gavinandresen:txndeadlock changing 1 files +21 −15
  1. gavinandresen commented at 5:45 PM on September 6, 2011: contributor

    Thanks to Pieter for the detective work finding this.

    Bug was a deadlock when the process-messages-thread and the IRC thread were adding peer addresses at the same time.

    I inspected the code for any other cases where starting a database transaction might trigger this type of bug, and all other cases are OK. I'll keep thinking about how to get the DEBUG_LOCKORDER code to detect this in the future.

    Tested by running bitcoind, letting it connect and startup (and join an IRC channel), then shutting it down repeatedly (10 times in a row) and observing no deadlocks.

  2. TheBlueMatt commented at 6:13 PM on September 6, 2011: member

    ACK

  3. Fix AddAddress cs_mapaddresses/db transaction deadlock 9406696578
  4. in src/net.cpp:None in 55b8833696 outdated
     442 | @@ -443,6 +443,10 @@ bool AddAddress(CAddress addr, int64 nTimePenalty, CAddrDB *pAddrDB)
     443 |      if (addr.ip == addrLocalHost.ip)
     444 |          return false;
     445 |      addr.nTime = max((int64)0, (int64)addr.nTime - nTimePenalty);
     446 | +    bool fUpdated = false;
     447 | +    bool fNew = false;
     448 | +    CAddress& addrFound = addr;
    


    sipa commented at 6:22 PM on September 6, 2011:

    I think this should not be a reference, as it would make the test on line 464 always fail.


    gavinandresen commented at 11:44 PM on September 6, 2011:

    Huh? The reference gets reassigned on line 463...


    sipa commented at 12:19 AM on September 7, 2011:

    You can't change what a reference refers to. The assignment operator (except for initialization) only overwrites the value referred to. Maybe you want a pointer, which gives you control over what is referenced.


    gavinandresen commented at 12:25 AM on September 7, 2011:

    Right you are, thanks for telling me I'm an idiot gently. Fixed (changed addrFound to a plain-old CAddress).

  5. sipa commented at 8:35 AM on September 7, 2011: member

    ACK

  6. gavinandresen referenced this in commit f92f022eda on Sep 7, 2011
  7. gavinandresen merged this on Sep 7, 2011
  8. gavinandresen closed this on Sep 7, 2011

  9. coblee referenced this in commit bdbe1819ce on Jul 17, 2012
  10. ptschip referenced this in commit 9a8cbaba99 on May 2, 2017
  11. MarcoFalke referenced this in commit 6899ef3f0e on Jun 11, 2019
  12. sidhujag referenced this in commit 0d7bb5013b on Jun 11, 2019
  13. kallewoof referenced this in commit 1dfef27322 on Oct 4, 2019
  14. rajarshimaitra referenced this in commit f040632e53 on Aug 5, 2021
  15. DrahtBot locked this on Sep 8, 2021

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-15 18:16 UTC

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