Details
-
Bug
-
Resolution: Fixed
-
Major
-
2.9.3
-
1
Description
We ran ThreadSanitizer on a binary using libcouchbase, and we get constant warnings about data race in libcouchbase[1]
According to the manual[2] using different lcb_t data structure between different threads should be thread-safe. But the lcb_next_rand64 function[3] defines static variables, so this doesn't hold.
[1]: ThreadSanitizer warning
WARNING: ThreadSanitizer: data race (pid=13) |
Read of size 8 at 0x7f48a75b9f20 by thread T5: |
#0 std::mersenne_twister_engine<unsigned long, 32ul, 624ul, 397ul, 31ul, 2567483615ul, 11ul, 4294967295ul, 7ul, 2636928640ul, 15ul, 4022730752ul, 18ul, 1812433253ul>::operator()() /usr/include/c++/5/bits/random.tcc:458 (crjw_server+0x0000009d1f55) |
#1 unsigned long std::uniform_int_distribution<unsigned long>::operator()<std::mersenne_twister_engine<unsigned long, 32ul, 624ul, 397ul, 31ul, 2567483615ul, 11ul, 4294967295ul, 7ul, 2636928640ul, 15ul, 4022730752ul, 18ul, 1812433253ul> >(std::mersenne_twister_engine<unsigned long, 32ul, 624ul, 397ul, 31ul, 2567483615ul, 11ul, 4294967295ul, 7ul, 2636928640ul, 15ul, 4022730752ul, 18ul, 1812433253ul>&, std::uniform_int_distribution<unsigned long>::param_type const&) /usr/include/c++/5/bits/uniform_int_dist.h:274 (crjw_server+0x000000f589c7) |
#2 unsigned long std::uniform_int_distribution<unsigned long>::operator()<std::mersenne_twister_engine<unsigned long, 32ul, 624ul, 397ul, 31ul, 2567483615ul, 11ul, 4294967295ul, 7ul, 2636928640ul, 15ul, 4022730752ul, 18ul, 1812433253ul> >(std::mersenne_twister_engine<unsigned long, 32ul, 624ul, 397ul, 31ul, 2567483615ul, 11ul, 4294967295ul, 7ul, 2636928640ul, 15ul, 4022730752ul, 18ul, 1812433253ul>&, std::uniform_int_distribution<unsigned long>::param_type const&) /usr/include/c++/5/bits/uniform_int_dist.h:268 (crjw_server+0x000000f5899c) |
#3 lcb_next_rand64 <null> (libcouchbase.so.2+0x00000007b9da) |
#4 boost::asio::detail::scheduler_operation::complete(void*, boost::system::error_code const&, unsigned long) /home/jenkins/workspace/DEVQA_UPDATE/label/LinuxBuildNode/thirdparty/boost/include/boost/asio/detail/scheduler_operation.hpp:40 (crjw_server+0x000000939c83) |
#5 boost::asio::detail::scheduler::do_run_one(boost::asio::detail::conditionally_enabled_mutex::scoped_lock&, boost::asio::detail::scheduler_thread_info&, boost::system::error_code const&) /home/jenkins/workspace/DEVQA_UPDATE/label/LinuxBuildNode/thirdparty/boost/include/boost/asio/detail/impl/scheduler.ipp:401 (crjw_server+0x000000939c83) |
#6 boost::asio::detail::scheduler::run(boost::system::error_code&) /home/jenkins/workspace/DEVQA_UPDATE/label/LinuxBuildNode/thirdparty/boost/include/boost/asio/detail/impl/scheduler.ipp:154 (crjw_server+0x000000939c83) |
#7 boost::asio::io_context::run() /home/jenkins/workspace/DEVQA_UPDATE/label/LinuxBuildNode/thirdparty/boost/include/boost/asio/impl/io_context.ipp:62 (crjw_server+0x0000009f9c6f) |
#8 operator() /home/jenkins/workspace/DEVQA_UPDATE/label/LinuxBuildNode/MobileServer/Database/CouchbaseBase.cpp:101 (crjw_server+0x0000009f9c6f) |
#9 _M_invoke /usr/include/c++/5/functional:1871 (crjw_server+0x0000009f9c6f) |
#10 std::function<void ()>::operator()() const /usr/include/c++/5/functional:2267 (crjw_server+0x000000c4f732) |
#11 RunCodeBlockWithTrace(std::function<void ()>) /home/jenkins/workspace/DEVQA_UPDATE/label/LinuxBuildNode/MobileServer/Util/CTracedCodeBlock.cpp:14 (crjw_server+0x000000c4f732) |
#12 operator() /home/jenkins/workspace/DEVQA_UPDATE/label/LinuxBuildNode/MobileServer/Database/CouchbaseBase.cpp:102 (crjw_server+0x0000009fdaf0) |
#13 _M_invoke<> /usr/include/c++/5/functional:1531 (crjw_server+0x0000009fdaf0) |
#14 operator() /usr/include/c++/5/functional:1520 (crjw_server+0x0000009fdaf0) |
#15 _M_run /usr/include/c++/5/thread:115 (crjw_server+0x0000009fdaf0) |
#16 <null> <null> (libstdc++.so.6+0x0000000b8c7f) |
|
Previous write of size 8 at 0x7f48a75b9f20 by thread T121: |
#0 std::mersenne_twister_engine<unsigned long, 32ul, 624ul, 397ul, 31ul, 2567483615ul, 11ul, 4294967295ul, 7ul, 2636928640ul, 15ul, 4022730752ul, 18ul, 1812433253ul>::operator()() /usr/include/c++/5/bits/random.tcc:462 (crjw_server+0x0000009d1f80) |
#1 unsigned long std::uniform_int_distribution<unsigned long>::operator()<std::mersenne_twister_engine<unsigned long, 32ul, 624ul, 397ul, 31ul, 2567483615ul, 11ul, 4294967295ul, 7ul, 2636928640ul, 15ul, 4022730752ul, 18ul, 1812433253ul> >(std::mersenne_twister_engine<unsigned long, 32ul, 624ul, 397ul, 31ul, 2567483615ul, 11ul, 4294967295ul, 7ul, 2636928640ul, 15ul, 4022730752ul, 18ul, 1812433253ul>&, std::uniform_int_distribution<unsigned long>::param_type const&) /usr/include/c++/5/bits/uniform_int_dist.h:274 (crjw_server+0x000000f589c7) |
#2 unsigned long std::uniform_int_distribution<unsigned long>::operator()<std::mersenne_twister_engine<unsigned long, 32ul, 624ul, 397ul, 31ul, 2567483615ul, 11ul, 4294967295ul, 7ul, 2636928640ul, 15ul, 4022730752ul, 18ul, 1812433253ul> >(std::mersenne_twister_engine<unsigned long, 32ul, 624ul, 397ul, 31ul, 2567483615ul, 11ul, 4294967295ul, 7ul, 2636928640ul, 15ul, 4022730752ul, 18ul, 1812433253ul>&, std::uniform_int_distribution<unsigned long>::param_type const&) /usr/include/c++/5/bits/uniform_int_dist.h:268 (crjw_server+0x000000f5899c) |
#3 lcb_next_rand64 <null> (libcouchbase.so.2+0x00000007b9da) |
#4 boost::asio::detail::scheduler_operation::complete(void*, boost::system::error_code const&, unsigned long) /home/jenkins/workspace/DEVQA_UPDATE/label/LinuxBuildNode/thirdparty/boost/include/boost/asio/detail/scheduler_operation.hpp:40 (crjw_server+0x000000939c83) |
#5 boost::asio::detail::scheduler::do_run_one(boost::asio::detail::conditionally_enabled_mutex::scoped_lock&, boost::asio::detail::scheduler_thread_info&, boost::system::error_code const&) /home/jenkins/workspace/DEVQA_UPDATE/label/LinuxBuildNode/thirdparty/boost/include/boost/asio/detail/impl/scheduler.ipp:401 (crjw_server+0x000000939c83) |
#6 boost::asio::detail::scheduler::run(boost::system::error_code&) /home/jenkins/workspace/DEVQA_UPDATE/label/LinuxBuildNode/thirdparty/boost/include/boost/asio/detail/impl/scheduler.ipp:154 (crjw_server+0x000000939c83) |
#7 boost::asio::io_context::run() /home/jenkins/workspace/DEVQA_UPDATE/label/LinuxBuildNode/thirdparty/boost/include/boost/asio/impl/io_context.ipp:62 (crjw_server+0x0000009f9c6f) |
#8 operator() /home/jenkins/workspace/DEVQA_UPDATE/label/LinuxBuildNode/MobileServer/Database/CouchbaseBase.cpp:101 (crjw_server+0x0000009f9c6f) |
#9 _M_invoke /usr/include/c++/5/functional:1871 (crjw_server+0x0000009f9c6f) |
#10 std::function<void ()>::operator()() const /usr/include/c++/5/functional:2267 (crjw_server+0x000000c4f732) |
#11 RunCodeBlockWithTrace(std::function<void ()>) /home/jenkins/workspace/DEVQA_UPDATE/label/LinuxBuildNode/MobileServer/Util/CTracedCodeBlock.cpp:14 (crjw_server+0x000000c4f732) |
#12 operator() /home/jenkins/workspace/DEVQA_UPDATE/label/LinuxBuildNode/MobileServer/Database/CouchbaseBase.cpp:102 (crjw_server+0x0000009fdaf0) |
#13 _M_invoke<> /usr/include/c++/5/functional:1531 (crjw_server+0x0000009fdaf0) |
#14 operator() /usr/include/c++/5/functional:1520 (crjw_server+0x0000009fdaf0) |
#15 _M_run /usr/include/c++/5/thread:115 (crjw_server+0x0000009fdaf0) |
#16 <null> <null> (libstdc++.so.6+0x0000000b8c7f) |
|
Location is global '<null>' of size 0 at 0x000000000000 (libcouchbase.so.2+0x0000002dcf20) |
|
SUMMARY: ThreadSanitizer: data race /usr/include/c++/5/bits/random.tcc:458 std::mersenne_twister_engine<unsigned long, 32ul, 624ul, 397ul, 31ul, 2567483615ul, 11ul, 4294967295ul, 7ul, 2636928640ul, 15ul, 4022730752ul, 18ul, 1812433253ul>::operator()() |
[2]: http://docs.couchbase.com/sdk-api/couchbase-c-client-2.8.3/lcb_thrsafe.html
[3]: https://github.com/couchbase/libcouchbase/blob/master/src/rnd.cc