-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Fix several potential issues found by sanitizers #9743
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
Conversation
src/httpserver.cpp
Outdated
{ | ||
std::lock_guard<std::mutex> lock(cs); |
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.
I don't understand this one. How could the ctor be racy?
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.
This is really confusing. I don't think we should be making this nonsensical change just to make a sanitizer tool happy.
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.
I'd highly prefer we do - such tools are pretty critical to our ability to find issues - but should probably have a comment noting why we have this insanity.
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.
The way forward would be to fix the tools, not contort our code around whatever happen to be the bugs in the analysis tools of the day.
It's not (see PR description). I think tsan is confused because it's accessed from another object. |
@@ -667,11 +667,13 @@ static void MutateTx(CMutableTransaction& tx, const std::string& command, | |||
MutateTxDelOutput(tx, commandVal); | |||
else if (command == "outaddr") | |||
MutateTxAddOutAddr(tx, commandVal); | |||
else if (command == "outpubkey") | |||
else if (command == "outpubkey") { | |||
if (!ecc) { ecc.reset(new Secp256k1Init()); } |
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.
Hmm... how can ecc
be a nullptr
at this point?
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.
Sorry,.. missed the fact that std::unique_ptr<Secp256k1Init> ecc;
initialises ecc
with nullptr
@jonasschnelli Where would it be set to something else? |
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
I'll try to find something less insane that also doesn't trip it. |
I'm unable to reproduce that tsan warning, so I just removed the commit. |
I think you forgot to push, it's still there: a10eff9 |
Rebased, and removed the LevelDB and the patches for spurious warning. The LevelDB patch should go through the leveldb repo instead. |
src/sync.cpp
Outdated
@@ -71,7 +71,7 @@ struct LockData { | |||
boost::mutex dd_mutex; | |||
} static lockdata; | |||
|
|||
boost::thread_specific_ptr<LockStack> lockstack; | |||
boost::thread_specific_ptr<LockStack> lockstack([](LockStack* ptr) { delete ptr; }); |
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.
I'm confused. The boost docs appear to indicate this should be identical.
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.
Agree, and tests seem to agree that they are indeed invoked. I'll remove it.
@@ -25,7 +28,7 @@ int64_t GetTime() | |||
|
|||
void SetMockTime(int64_t nMockTimeIn) | |||
{ | |||
nMockTime = nMockTimeIn; | |||
nMockTime.store(nMockTimeIn, std::memory_order_relaxed); |
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.
relaxed here just seems needlessly lossy - mocktime is for testing, it can be slow, and running a test with a race because we're using relaxed everyhwere just seems needlessly confusing.
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.
It's read by a relaxed read anyway, using a stronger serializing write won't matter (if I understand the semantics correctly).
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.
Yes, my suggestion was to change the read as well :)
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.
GetTime is called all over the place, no? I don't want to introduce extra synchronization there.
utACK 1d31093 |
1d31093 fix tsan: utiltime race on nMockTime (Pieter Wuille) 321bbc2 fix ubsan: bitcoin-tx: not initialize context before IsFullyValid (Pieter Wuille) Tree-SHA512: 39ea83c6122f06339cd425deb236357694e84ce2e4e9c61c10b90a8909b6e42e8c7b76396175cdc4723ababd2fa4f935d48f8a469baf853c5a06d7b962a5c8dc
1d31093 fix tsan: utiltime race on nMockTime (Pieter Wuille) 321bbc2 fix ubsan: bitcoin-tx: not initialize context before IsFullyValid (Pieter Wuille) Tree-SHA512: 39ea83c6122f06339cd425deb236357694e84ce2e4e9c61c10b90a8909b6e42e8c7b76396175cdc4723ababd2fa4f935d48f8a469baf853c5a06d7b962a5c8dc
1d31093 fix tsan: utiltime race on nMockTime (Pieter Wuille) 321bbc2 fix ubsan: bitcoin-tx: not initialize context before IsFullyValid (Pieter Wuille) Tree-SHA512: 39ea83c6122f06339cd425deb236357694e84ce2e4e9c61c10b90a8909b6e42e8c7b76396175cdc4723ababd2fa4f935d48f8a469baf853c5a06d7b962a5c8dc
1d31093 fix tsan: utiltime race on nMockTime (Pieter Wuille) 321bbc2 fix ubsan: bitcoin-tx: not initialize context before IsFullyValid (Pieter Wuille) Tree-SHA512: 39ea83c6122f06339cd425deb236357694e84ce2e4e9c61c10b90a8909b6e42e8c7b76396175cdc4723ababd2fa4f935d48f8a469baf853c5a06d7b962a5c8dc
1d31093 fix tsan: utiltime race on nMockTime (Pieter Wuille) 321bbc2 fix ubsan: bitcoin-tx: not initialize context before IsFullyValid (Pieter Wuille) Tree-SHA512: 39ea83c6122f06339cd425deb236357694e84ce2e4e9c61c10b90a8909b6e42e8c7b76396175cdc4723ababd2fa4f935d48f8a469baf853c5a06d7b962a5c8dc
1d31093 fix tsan: utiltime race on nMockTime (Pieter Wuille) 321bbc2 fix ubsan: bitcoin-tx: not initialize context before IsFullyValid (Pieter Wuille) Tree-SHA512: 39ea83c6122f06339cd425deb236357694e84ce2e4e9c61c10b90a8909b6e42e8c7b76396175cdc4723ababd2fa4f935d48f8a469baf853c5a06d7b962a5c8dc
1d31093 fix tsan: utiltime race on nMockTime (Pieter Wuille) 321bbc2 fix ubsan: bitcoin-tx: not initialize context before IsFullyValid (Pieter Wuille) Tree-SHA512: 39ea83c6122f06339cd425deb236357694e84ce2e4e9c61c10b90a8909b6e42e8c7b76396175cdc4723ababd2fa4f935d48f8a469baf853c5a06d7b962a5c8dc
1d31093 fix tsan: utiltime race on nMockTime (Pieter Wuille) 321bbc2 fix ubsan: bitcoin-tx: not initialize context before IsFullyValid (Pieter Wuille) Tree-SHA512: 39ea83c6122f06339cd425deb236357694e84ce2e4e9c61c10b90a8909b6e42e8c7b76396175cdc4723ababd2fa4f935d48f8a469baf853c5a06d7b962a5c8dc
1d31093 fix tsan: utiltime race on nMockTime (Pieter Wuille) 321bbc2 fix ubsan: bitcoin-tx: not initialize context before IsFullyValid (Pieter Wuille) Tree-SHA512: 39ea83c6122f06339cd425deb236357694e84ce2e4e9c61c10b90a8909b6e42e8c7b76396175cdc4723ababd2fa4f935d48f8a469baf853c5a06d7b962a5c8dc
1d31093 fix tsan: utiltime race on nMockTime (Pieter Wuille) 321bbc2 fix ubsan: bitcoin-tx: not initialize context before IsFullyValid (Pieter Wuille) Tree-SHA512: 39ea83c6122f06339cd425deb236357694e84ce2e4e9c61c10b90a8909b6e42e8c7b76396175cdc4723ababd2fa4f935d48f8a469baf853c5a06d7b962a5c8dc
1d31093 fix tsan: utiltime race on nMockTime (Pieter Wuille) 321bbc2 fix ubsan: bitcoin-tx: not initialize context before IsFullyValid (Pieter Wuille) Tree-SHA512: 39ea83c6122f06339cd425deb236357694e84ce2e4e9c61c10b90a8909b6e42e8c7b76396175cdc4723ababd2fa4f935d48f8a469baf853c5a06d7b962a5c8dc
1d31093 fix tsan: utiltime race on nMockTime (Pieter Wuille) 321bbc2 fix ubsan: bitcoin-tx: not initialize context before IsFullyValid (Pieter Wuille) Tree-SHA512: 39ea83c6122f06339cd425deb236357694e84ce2e4e9c61c10b90a8909b6e42e8c7b76396175cdc4723ababd2fa4f935d48f8a469baf853c5a06d7b962a5c8dc
267ee79 fix tsan: utiltime race on nMockTime (Pieter Wuille) be2b6b5 fix ubsan: bitcoin-tx: not initialize context before IsFullyValid (Pieter Wuille) bb65b9e [Refactoring] Additions/updates to pivx-tx.cpp (random-zebra) 2c944c7 [Refactoring] Add SEQUENCE_FINAL constant in CTxIn (random-zebra) 4501198 [Refactoring] Move non-throwing ParseHashStr from rest to core_read (random-zebra) 29e23bf [Refactoring] Add constant for max pubkeys per multisig (random-zebra) Pull request description: Simple refactoring + backport bitcoin#9743 ACKs for top commit: Fuzzbawls: ACK 267ee79 furszy: looking good, utACK 267ee79 and merging.. Tree-SHA512: a46c46ea3b9b3e625b13978448787b0afbd9233a1893dea0a400abb3aa7c73524968453d5955ceca991f587a431daed0f4a44744b4bfdd8360d591355f40c8cf
Notes:
After these, I believe our unit and rpc tests are clean for asan/lsan/ubsan/tsan, but:
deadlock:__db_pthread_mutex_lock
in it, and pass an environment variableTSAN_OPTIONS="suppressions=$file"
to the binaries.-DBOOST_SP_USE_STD_ATOMIC
to avoid tsan incorrectly detecting signals2 calls as racy (boost uses inline assembly for atomic refcounting by default, unless this compile options is passed; it was introduced in 1.54 I think).As tsan seems to become a usable option for race detection, I wonder if over time we could remove our own DEBUG_LOCKORDER features.