-
Notifications
You must be signed in to change notification settings - Fork 36.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean up all known races/platform-specific UB at the time PR was opened #9708
Clean up all known races/platform-specific UB at the time PR was opened #9708
Conversation
Concept ACK. Lightly tested ack. Getting these cleaned up makes it much easier to use tools that catch serious bugs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
light utACK 74b46ed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
src/net.cpp
Outdated
|
||
void CNode::MaybeSetAddrName(const std::string& addrNameIn) { | ||
LOCK(cs_addrName); | ||
if (addrName == "") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: .empty() please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
74b46ed
to
a51ecf7
Compare
I added clang annotations for everything in net (I think) that's guarded by a mutex, and built with -Wthread-safety: theuni@df50d4f This reveals that nearly all is good, with these exceptions: theuni@d185ca0 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 So, options are:
I'm fine with any of the above. |
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 |
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 a51ecf7 |
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
a51ecf7
to
db2dc7a
Compare
Rebased to fix a trivial merge conflict. |
re-ACK db2dc7a |
ACK db2dc7a. Running a node with master + this PR, with many connections, compiled with -fsanitize=thread -fsanitize=undefined. Only these cases are detected:
|
…e PR was opened db2dc7a Move CNode::addrLocal access behind locked accessors (Matt Corallo) 036073b Move CNode::addrName accesses behind locked accessors (Matt Corallo) d8f2b8a Make nTimeBestReceived atomic (Matt Corallo) 22b4966 Move [clean|str]SubVer writes/copyStats into a lock (Matt Corallo) 0f31872 Make nServices atomic (Matt Corallo) 96f42d8 Make nStartingHeight atomic (Matt Corallo) 512731b Access fRelayTxes with cs_filter lock in copyStats (Matt Corallo) ae683c1 Avoid copying CNodeStats to make helgrind OK with buggy std::string (Matt Corallo) 644f123 Make nTimeConnected const in CNode (Matt Corallo) 321d0fc net: fix a few races. Credit @TheBlueMatt (Cory Fields)
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 zcash: cherry picked from commit 321d0fc zcash: bitcoin/bitcoin#9708
zcash: cherry picked from commit 644f123 zcash: bitcoin/bitcoin#9708
zcash: cherry picked from commit ae683c1 zcash: bitcoin/bitcoin#9708
zcash: cherry picked from commit 512731b zcash: bitcoin/bitcoin#9708
zcash: cherry picked from commit 96f42d8 zcash: bitcoin/bitcoin#9708
zcash: cherry picked from commit 0f31872 zcash: bitcoin/bitcoin#9708
zcash: cherry picked from commit 22b4966 zcash: bitcoin/bitcoin#9708
zcash: cherry picked from commit d8f2b8a zcash: bitcoin/bitcoin#9708
zcash: cherry picked from commit 036073b zcash: bitcoin/bitcoin#9708
zcash: cherry picked from commit db2dc7a zcash: bitcoin/bitcoin#9708
Bitcoin 0.14 locking PRs These are locking changes from upstream (bitcoin core) release 0.14, oldest to newest (when merged to the master branch). Each commit also includes a reference both to the PR and the upstream commit. - bitcoin/bitcoin#8472 - bitcoin/bitcoin#8606 - Excludes a lock move because we don't have bitcoin/bitcoin#7840 which this move was partially-reverting. - bitcoin/bitcoin#9230 - Only first commit (we don't have `LogTimestampStr` anymore). - bitcoin/bitcoin#9243 - Only the sixth commit, excluding `IsArgSet` locking (we haven't pulled that function in yet). - bitcoin/bitcoin#9626 - The cherry-picked commit does not match the upstream at all, but the resulting lock is useful. - bitcoin/bitcoin#9679 - bitcoin/bitcoin#9227 - bitcoin/bitcoin#9698 - Excludes change to `CConnman::PushMessage` in second commit (which we don't have yet). - bitcoin/bitcoin#9708 - bitcoin/bitcoin#9771
zcash: cherry picked from commit 512731b zcash: bitcoin/bitcoin#9708
zcash: cherry picked from commit 512731b zcash: bitcoin/bitcoin#9708
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.