net: Add Clang thread safety annotations for guarded variables in the networking code #13123

pull practicalswift wants to merge 2 commits into bitcoin:master from practicalswift:net-guarded-by changing 3 files +28 −34
  1. practicalswift commented at 8:47 am on April 30, 2018: contributor

    Add Clang thread safety annotations for variables guarded by:

    • cs_addrLocal
    • cs_addrName
    • cs_feeFilter
    • cs_filter
    • cs_hSocket
    • cs_inventory
    • cs_mapLocalHost
    • cs_most_recent_block
    • cs_proxyInfos
    • cs_sendProcessing
    • cs_setBanned
    • cs_SubVer
    • cs_vOneShots
    • cs_vProcessMsg
    • cs_vRecv
    • cs_vSend

    Changed files:

    • src/net.{cpp,h}
    • src/netbase.cpp
  2. practicalswift renamed this:
    Add Clang thread safety annotations for guarded variables in the networking code
    net: Add Clang thread safety annotations for guarded variables in the networking code
    on Apr 30, 2018
  3. fanquake added the label Refactoring on Apr 30, 2018
  4. fanquake added the label P2P on Apr 30, 2018
  5. DrahtBot added the label Needs rebase on Jul 9, 2018
  6. practicalswift force-pushed on Jul 11, 2018
  7. practicalswift commented at 11:26 pm on July 11, 2018: contributor
    Rebased!
  8. DrahtBot removed the label Needs rebase on Jul 12, 2018
  9. MarcoFalke commented at 10:05 pm on August 12, 2018: member
    Imo could squash everything, since most of the commits only touch 2 lines.
  10. practicalswift force-pushed on Aug 13, 2018
  11. practicalswift commented at 7:39 am on August 13, 2018: contributor
    @MarcoFalke Rebased and squashed! Please re-review :-)
  12. practicalswift force-pushed on Aug 30, 2018
  13. practicalswift commented at 1:37 pm on August 30, 2018: contributor

    Rebased and added missing lock:

     0diff --git a/src/net.cpp b/src/net.cpp
     1index 529a2f82f..7fcf6a3ef 100644
     2--- a/src/net.cpp
     3+++ b/src/net.cpp
     4@@ -715,7 +715,10 @@ void CNode::copyStats(CNodeStats &stats)
     5         X(nRecvBytes);
     6     }
     7     X(fWhitelisted);
     8-    X(minFeeFilter);
     9+    {
    10+        LOCK(cs_feeFilter);
    11+        X(minFeeFilter);
    12+    }
    13
    14     // It is common for nodes with good ping times to suddenly become lagged,
    15     // due to a new block arriving or other large transfer.
    
  14. in src/net.h:640 in 36ecc9ee38 outdated
    630-    std::deque<std::vector<unsigned char>> vSendMsg;
    631     CCriticalSection cs_vSend;
    632-    CCriticalSection cs_hSocket;
    633+    uint64_t nSendBytes GUARDED_BY(cs_vSend);
    634+    std::deque<std::vector<unsigned char>> vSendMsg GUARDED_BY(cs_vSend);
    635     CCriticalSection cs_vRecv;
    


    Empact commented at 7:11 am on September 2, 2018:
    nit: move this down?
  15. in src/net.h:665 in 36ecc9ee38 outdated
    652@@ -653,8 +653,8 @@ class CNode
    653     // to be printed out, displayed to humans in various forms and so on. So we sanitize it and
    654     // store the sanitized version in cleanSubVer. The original should be used when dealing with
    655     // the network or wire types and the cleaned string used when displayed or logged.
    656-    std::string strSubVer, cleanSubVer;
    657     CCriticalSection cs_SubVer; // used for both cleanSubVer and strSubVer
    658+    std::string strSubVer GUARDED_BY(cs_SubVer), cleanSubVer GUARDED_BY(cs_SubVer);
    


    Empact commented at 7:14 am on September 2, 2018:
    nit: separate lines?
  16. in src/net.h:675 in 36ecc9ee38 outdated
    673+    bool fRelayTxes GUARDED_BY(cs_filter);
    674     bool fSentAddr;
    675     CSemaphoreGrant grantOutbound;
    676-    CCriticalSection cs_filter;
    677-    std::unique_ptr<CBloomFilter> pfilter;
    678+    std::unique_ptr<CBloomFilter> pfilter GUARDED_BY(cs_filter);
    


    Empact commented at 7:16 am on September 2, 2018:
    PT_GUARDED_BY?
  17. DrahtBot commented at 10:37 pm on September 20, 2018: member

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #14605 (Return of the Banman by dongcarl)
    • #14046 (net: Refactor message parsing (CNetMessage), adds flexibility by jonasschnelli)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  18. practicalswift force-pushed on Oct 8, 2018
  19. practicalswift commented at 1:30 pm on October 8, 2018: contributor
    @MarcoFalke @Empact Updated. Please re-review :-)
  20. practicalswift force-pushed on Oct 8, 2018
  21. practicalswift force-pushed on Oct 8, 2018
  22. practicalswift force-pushed on Oct 8, 2018
  23. practicalswift force-pushed on Oct 8, 2018
  24. practicalswift force-pushed on Oct 8, 2018
  25. practicalswift force-pushed on Oct 8, 2018
  26. practicalswift force-pushed on Oct 8, 2018
  27. DrahtBot added the label Needs rebase on Nov 27, 2018
  28. practicalswift force-pushed on Nov 27, 2018
  29. DrahtBot removed the label Needs rebase on Nov 27, 2018
  30. in src/net.h:677 in 559e910a4f outdated
    673@@ -673,15 +674,15 @@ class CNode
    674     const bool fInbound;
    675     std::atomic_bool fSuccessfullyConnected;
    676     std::atomic_bool fDisconnect;
    677+    mutable CCriticalSection cs_filter;
    


    MarcoFalke commented at 8:05 pm on November 27, 2018:
    Is moving those lines required? It makes automated review harder, so best to keep them where they were?

    practicalswift commented at 8:01 am on November 28, 2018:
    Good point! Fixed. Please re-review :-)
  31. practicalswift force-pushed on Nov 28, 2018
  32. Add missing locking annotations b312cd7707
  33. Add missing lock in CNode::copyStats(...) 4894133dc5
  34. practicalswift force-pushed on Nov 28, 2018
  35. MarcoFalke commented at 4:05 pm on November 28, 2018: member

    utACK 4894133dc5095ed971bf98d695384e7cbb16e54c

    • Checked that where the lock is added is also a place where tsan would complain [1]
    • Checked that the lock annotations don’t change the objdump of the bitcoind, compiled with gcc or clang on my system

    [1]

    0WARNING: ThreadSanitizer: data race (pid=30947)
    1  Read of size 8 at 0x7d6c0005e688 by thread T12 (mutexes: write M131981):
    2    [#0](/bitcoin-bitcoin/0/) CNode::copyStats(CNodeStats&) /bitcoin/src/net.cpp:718 (bitcoind+0x0000005224e5)
    3    [#1](/bitcoin-bitcoin/1/) CConnman::GetNodeStats(std::vector<CNodeStats, std::allocator<CNodeStats> >&) /bitcoin/src/net.cpp:2567 (bitcoind+0x0000005346b7)
    4    [#2](/bitcoin-bitcoin/2/) getpeerinfo(JSONRPCRequest const&) /bitcoin/src/rpc/net.cpp:131 (bitcoind+0x000000617137)
    5
    6...
    7
    8  Previous write of size 8 at 0x7d6c0005e688 by thread T19 (mutexes: write M134272):
    9    [#0](/bitcoin-bitcoin/0/) ProcessMessage(CNode*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, CDataStream&, long, CChainParams const&, CConnman*, std::atomic<bool> const&, bool) /bitcoin/src/net_processing.cpp:2927 (bitcoind+0x000000562dc8)
    
  36. MarcoFalke referenced this in commit 0a452d02ce on Nov 28, 2018
  37. MarcoFalke merged this on Nov 28, 2018
  38. MarcoFalke closed this on Nov 28, 2018

  39. PastaPastaPasta referenced this in commit 75d5fec88b on Apr 12, 2020
  40. PastaPastaPasta referenced this in commit dd1e7e4ce0 on Apr 16, 2020
  41. PastaPastaPasta referenced this in commit a13e2f4355 on Apr 16, 2020
  42. jnewbery commented at 1:02 pm on June 22, 2020: member
    @practicalswift why are nNextAddrSend and nNextLocalAddrSend now guarded by cs_sendProcessing? I don’t think those things should be connected.
  43. practicalswift commented at 1:10 pm on June 22, 2020: contributor
    @jnewbery I agree that sure looks like an error! Good catch!
  44. jnewbery commented at 1:19 pm on June 22, 2020: member
    Thanks for the quick reply. I have a PR moving some of those fields around, so I’ll get rid of the lock annotations there.
  45. practicalswift commented at 2:18 pm on June 22, 2020: contributor
    @jnewbery Thanks a lot for fixing (and finding)! Much appreciated!
  46. jnewbery commented at 2:44 pm on June 22, 2020: member
    @practicalswift sorry I meant to say that I have a branch that moves the fields around that I haven’t PR’ed yet. I’ll ping you when the PR is open.
  47. naumenkogs referenced this in commit ed5c6deacc on Oct 6, 2020
  48. naumenkogs referenced this in commit e8da279a38 on Oct 6, 2020
  49. naumenkogs referenced this in commit c3ad35e367 on Oct 7, 2020
  50. naumenkogs referenced this in commit 836d4fb5d0 on Oct 13, 2020
  51. jnewbery referenced this in commit 9dc6124e92 on Oct 13, 2020
  52. naumenkogs referenced this in commit 0d9322f9c2 on Dec 9, 2020
  53. naumenkogs referenced this in commit 6fe9af6f88 on Dec 9, 2020
  54. naumenkogs referenced this in commit 8c9b306986 on Dec 10, 2020
  55. naumenkogs referenced this in commit ba6dc3576d on Dec 18, 2020
  56. jnewbery referenced this in commit c001ba45f1 on Feb 28, 2021
  57. jnewbery commented at 11:53 am on February 28, 2021: member

    @practicalswift sorry I meant to say that I have a branch that moves the fields around that I haven’t PR’ed yet. I’ll ping you when the PR is open.

    PR is open here: #21236. It’s a pure refactor and should be easy to review.

  58. jnewbery referenced this in commit 6a956bafd4 on Mar 1, 2021
  59. ckti referenced this in commit 4120fb71f7 on Mar 28, 2021
  60. LarryRuane referenced this in commit 5ea5a52636 on Apr 5, 2021
  61. LarryRuane referenced this in commit 716f2c6984 on Apr 5, 2021
  62. practicalswift deleted the branch on Apr 10, 2021
  63. LarryRuane referenced this in commit a535339c1b on Apr 29, 2021
  64. LarryRuane referenced this in commit 98f7b77d65 on Apr 29, 2021
  65. LarryRuane referenced this in commit b4fcee0614 on Jun 1, 2021
  66. LarryRuane referenced this in commit bcf71e925c on Jun 1, 2021
  67. gades referenced this in commit 8d8d47fb36 on Jun 25, 2021
  68. gades referenced this in commit 9c05585999 on Feb 8, 2022
  69. DrahtBot locked this on Aug 18, 2022

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: 2024-11-17 09:12 UTC

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