[zeromq-dev] Race condition in socket creation

Michi Henning michi at triodia.com
Tue Dec 31 05:30:57 CET 2013


Here is a minimal test case:

#include <zmqpp/zmqpp.hpp>

int main()
{
     zmqpp::context c;
     zmqpp::socket s(c, zmqpp::socket_type::publish);
}

When I compile this with Clang's thread sanitizer and run it, I get:

==================
WARNING: ThreadSanitizer: data race (pid=4369)
   Read of size 8 at 0x7da000008090 by thread T1:
     #0 epoll_ctl ??:0 (exe+0x00000002baab)
     #1 std::vector<unsigned int, std::allocator<unsigned int> 
 >::_M_insert_aux(__gnu_cxx::__normal_iterator<unsigned int*, 
std::vector<unsigned int, std::allocator<unsigned int> > >, unsigned int 
const&) ??:0 (libzmq.so.3+0x0000000149d1)

   Previous write of size 8 at 0x7da000008090 by main thread (mutexes: 
write M9):
     #0 eventfd ??:0 (exe+0x0000000288e0)
     #1 std::vector<unsigned int, std::allocator<unsigned int> 
 >::_M_insert_aux(__gnu_cxx::__normal_iterator<unsigned int*, 
std::vector<unsigned int, std::allocator<unsigned int> > >, unsigned int 
const&) ??:0 (libzmq.so.3+0x000000026b18)
     #2 __libc_start_main /build/buildd/eglibc-2.17/csu/libc-start.c:260 
(libc.so.6+0x000000021de4)

   Location is file descriptor 9 created by main thread at:
     #0 eventfd ??:0 (exe+0x0000000288e0)
     #1 std::vector<unsigned int, std::allocator<unsigned int> 
 >::_M_insert_aux(__gnu_cxx::__normal_iterator<unsigned int*, 
std::vector<unsigned int, std::allocator<unsigned int> > >, unsigned int 
const&) ??:0 (libzmq.so.3+0x000000026b18)
     #2 __libc_start_main /build/buildd/eglibc-2.17/csu/libc-start.c:260 
(libc.so.6+0x000000021de4)

   Mutex M9 created at:
     #0 pthread_mutex_init ??:0 (exe+0x0000000242c5)
     #1 char* std::string::_S_construct<char*>(char*, char*, 
std::allocator<char> const&, std::forward_iterator_tag) ??:0 
(libzmq.so.3+0x000000010966)
     #2 context /usr/local/include/zmqpp/context.hpp:77 (exe+0x000000052a30)
     #3 main /home/michi/src/unity-scopes-api/zmq/zmqpp_test.cpp:5 
(exe+0x0000000528e0)

   Thread T1 (tid=4371, running) created by main thread at:
     #0 pthread_create ??:0 (exe+0x000000023d12)
     #1 std::vector<unsigned int, std::allocator<unsigned int> 
 >::_M_insert_aux(__gnu_cxx::__normal_iterator<unsigned int*, 
std::vector<unsigned int, std::allocator<unsigned int> > >, unsigned int 
const&) ??:0 (libzmq.so.3+0x000000030b4c)
     #2 __libc_start_main /build/buildd/eglibc-2.17/csu/libc-start.c:260 
(libc.so.6+0x000000021de4)

SUMMARY: ThreadSanitizer: data race ??:0 epoll_ctl
==================
ThreadSanitizer: reported 1 warnings

I'm seeing this with zmq version 3.2.3.

I don't believe this should be happening?

Thanks,

Michi.



More information about the zeromq-dev mailing list