Notes:
- The LevelDB patch here is simple, and makes it switch to c++11 atomics when available over their MemoryBarrier() based solutions. A slightly better version is submitted upstream as https://github.com/google/leveldb/pull/449.
- Several race fixes are not bug fixes (the numThreads one and the access to globals one both happen before any multithreaded access to those variables takes place; and the LevelDB one is due to tsan not recognizing the inline assembly used in MemoryBarrier), but in general improvements that result in less fragile code.
After these, I believe our unit and rpc tests are clean for asan/lsan/ubsan/tsan, but:
- The BDB environment holds locks that cross call stacks, and trigger the tsan deadlock detection. To avoid, create a suppressions file with the line
deadlock:__db_pthread_mutex_lock
in it, and pass an environment variableTSAN_OPTIONS="suppressions=$file"
to the binaries. - The zapwallettxn RPC test causes an assertion failure inside libtsan for me.
- You need to compile with
-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.