Clean up all known races/platform-specific UB at the time PR was opened #9708

pull TheBlueMatt wants to merge 10 commits into bitcoin:master from TheBlueMatt:2017-02-fix-copystats-races changing 3 files +105 −45
  1. TheBlueMatt commented at 3:26 PM on February 7, 2017: member

    Because we (finally) have C++11, there is no excuse for using ints/flags/anything concurrently.

    #9695 (which this is based on) got most of them, but the last two (addrName and addrLocal) were left out because they might need more discussion. Here I opted for giving them a wrapper which does locked access, though that does mean creating copies of them during use.

  2. fanquake added the label P2P on Feb 7, 2017
  3. fanquake added the label Refactoring on Feb 7, 2017
  4. gmaxwell commented at 9:26 PM on February 7, 2017: contributor

    Concept ACK. Lightly tested ack. Getting these cleaned up makes it much easier to use tools that catch serious bugs.

  5. dcousens approved
  6. dcousens commented at 2:31 AM on February 8, 2017: contributor

    light utACK 74b46ed

  7. gmaxwell approved
  8. gmaxwell commented at 4:45 PM on February 9, 2017: contributor

    ACK

  9. laanwj added this to the milestone 0.14.0 on Feb 9, 2017
  10. in src/net.cpp:None in 8471a3405c outdated
     598 | +    return addrName;
     599 | +}
     600 | +
     601 | +void CNode::MaybeSetAddrName(const std::string& addrNameIn) {
     602 | +    LOCK(cs_addrName);
     603 | +    if (addrName == "") {
    


    theuni commented at 7:54 PM on February 9, 2017:

    nit: .empty() please


    TheBlueMatt commented at 10:16 PM on February 9, 2017:

    Fixed.

  11. TheBlueMatt force-pushed on Feb 9, 2017
  12. theuni commented at 12:27 AM on February 10, 2017: member

    I added clang annotations for everything in net (I think) that's guarded by a mutex, and built with -Wthread-safety: https://github.com/theuni/bitcoin/commit/df50d4fabc71a175c3faa0fcf74ded856ea35709

    This reveals that nearly all is good, with these exceptions: https://github.com/theuni/bitcoin/commit/d185ca0840f8107b2cf4307f51d703e849532928

    The only one that we really need to worry about for 0.14 is the cs_filter locking. However, because cs_filter is locked from net_processing with a wide scope in a few places, I'm not confident that the LOCK(cs_filter) in AttemptToEvictConnection() can't deadlock due to ordering.

    So, options are:

    I'm fine with any of the above.

  13. TheBlueMatt renamed this:
    Clean Up all known races/platform-specific UB
    Clean up all known races/platform-specific UB at the time PR was opened
    on Feb 10, 2017
  14. theuni commented at 5:45 AM on February 10, 2017: member

    Heh, title change comes from IRC discussion. The race mentioned above is not new, and not likely to cause issues. It's not worth holding up 0.14 for another set of ACKs or another PR to review.

    If anyone strongly disagrees I'll PR a fix, but I'm ok with leaving it alone.

    ACK a51ecf7ce00096bf607d15227ff1e1e39a3f6803

  15. laanwj commented at 9:41 AM on February 10, 2017: member

    What should hold up the release are critical issues, e.g. those that can (or do) cause crashes, and corruption. Fixing every little thing static and dynamic analyzers can complain about is not part of that, and can be done later.

    utACK https://github.com/bitcoin/bitcoin/commit/a51ecf7ce00096bf607d15227ff1e1e39a3f6803

  16. net: fix a few races. Credit @TheBlueMatt
    These are (afaik) all long-standing races or concurrent accesses. Going
    forward, we can clean these up so that they're not all individual atomic
    accesses.
    
    - Reintroduce cs_vRecv to guard receive-specific vars
    - Lock vRecv/vSend for CNodeStats
    - Make some vars atomic.
    - Only set the connection time in CNode's constructor so that it doesn't change
    321d0fc6b6
  17. Make nTimeConnected const in CNode 644f1234e2
  18. Avoid copying CNodeStats to make helgrind OK with buggy std::string ae683c1b19
  19. Access fRelayTxes with cs_filter lock in copyStats 512731bed0
  20. Make nStartingHeight atomic 96f42d8a12
  21. Make nServices atomic 0f31872615
  22. Move [clean|str]SubVer writes/copyStats into a lock 22b4966a29
  23. Make nTimeBestReceived atomic d8f2b8a8c0
  24. Move CNode::addrName accesses behind locked accessors 036073bf87
  25. Move CNode::addrLocal access behind locked accessors db2dc7a58c
  26. TheBlueMatt force-pushed on Feb 10, 2017
  27. TheBlueMatt commented at 4:32 PM on February 10, 2017: member

    Rebased to fix a trivial merge conflict.

  28. theuni commented at 7:22 PM on February 10, 2017: member

    re-ACK db2dc7a58cb0a3df58188b748df8e0d04ba76f00

  29. sipa commented at 10:02 PM on February 10, 2017: member

    ACK db2dc7a58cb0a3df58188b748df8e0d04ba76f00. Running a node with master + this PR, with many connections, compiled with -fsanitize=thread -fsanitize=undefined. Only these cases are detected:

    • BDB's internal locks (which persist across call stacks, bleh) trigger lock inversion detections.
    • leveldb::port::AtomicPointer isn't recognized as an atomic (and should probably be replaced with c++11 std::atomic<T*>).
    • A suprious race is detected in httpserver.cpp's WorkQueue constructor.
  30. sipa merged this on Feb 11, 2017
  31. sipa closed this on Feb 11, 2017

  32. sipa referenced this in commit a06ede9a13 on Feb 11, 2017
  33. codablock referenced this in commit 0cef77cd8b on Jan 19, 2018
  34. codablock referenced this in commit b50b8196fa on Jan 23, 2018
  35. HashUnlimited referenced this in commit b75d7f2e6d on Feb 27, 2018
  36. andvgal referenced this in commit 5a50e49aaa on Jan 6, 2019
  37. CryptoCentric referenced this in commit 3c554872a0 on Feb 27, 2019
  38. random-zebra referenced this in commit 777638e7bc on Aug 27, 2020
  39. random-zebra referenced this in commit cbd9271afb on Sep 7, 2020
  40. LarryRuane referenced this in commit 1be59433e4 on Feb 24, 2021
  41. LarryRuane referenced this in commit cb17be1343 on Feb 24, 2021
  42. LarryRuane referenced this in commit a6896744bd on Feb 24, 2021
  43. LarryRuane referenced this in commit 627144234a on Feb 24, 2021
  44. LarryRuane referenced this in commit 1e3cfc24ae on Feb 24, 2021
  45. LarryRuane referenced this in commit daee68a86a on Feb 24, 2021
  46. LarryRuane referenced this in commit ce3f87af17 on Feb 24, 2021
  47. LarryRuane referenced this in commit d3a3782bd5 on Feb 24, 2021
  48. LarryRuane referenced this in commit 3c5273cb91 on Feb 24, 2021
  49. LarryRuane referenced this in commit bf565ea686 on Feb 24, 2021
  50. LarryRuane referenced this in commit 51fb0415c9 on Apr 1, 2021
  51. LarryRuane referenced this in commit 208a1a5867 on Apr 1, 2021
  52. LarryRuane referenced this in commit 5d3586f707 on Apr 1, 2021
  53. LarryRuane referenced this in commit 89b84b18ce on Apr 1, 2021
  54. LarryRuane referenced this in commit e25e59a74d on Apr 1, 2021
  55. LarryRuane referenced this in commit 830faf7005 on Apr 1, 2021
  56. LarryRuane referenced this in commit 5e9336adb1 on Apr 1, 2021
  57. LarryRuane referenced this in commit 1807076deb on Apr 1, 2021
  58. LarryRuane referenced this in commit 869e3bea3b on Apr 1, 2021
  59. LarryRuane referenced this in commit cb1bc21756 on Apr 1, 2021
  60. str4d referenced this in commit c2c43e39b2 on Apr 1, 2021
  61. str4d referenced this in commit 651c46a4b3 on Apr 1, 2021
  62. str4d referenced this in commit 676e7814f3 on Apr 1, 2021
  63. str4d referenced this in commit 78e0b89750 on Apr 1, 2021
  64. str4d referenced this in commit e6eac19062 on Apr 1, 2021
  65. str4d referenced this in commit 116deeec5b on Apr 1, 2021
  66. str4d referenced this in commit c9e2172eb6 on Apr 1, 2021
  67. zkbot referenced this in commit 1b5f17c900 on Apr 1, 2021
  68. zkbot referenced this in commit 80e66e7daa on Apr 2, 2021
  69. LarryRuane referenced this in commit 79ed4a293b on Apr 26, 2021
  70. LarryRuane referenced this in commit bd8eca9fd3 on Jun 1, 2021
  71. 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-18 18:15 UTC

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