From: Mark Andrews Date: Wed, 23 Sep 2020 03:54:06 +0000 (+1000) Subject: It appears that you can't change what you are polling for while connecting. X-Git-Tag: v9.17.6~36^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c37b251eb98d673716ad1e9d80e6f4deeb23bdb9;p=thirdparty%2Fbind9.git It appears that you can't change what you are polling for while connecting. WARNING: ThreadSanitizer: data race Read of size 8 at 0x000000000001 by thread T1 (mutexes: write M1): #0 epoll_ctl #1 watch_fd lib/isc/unix/socket.c:704:8 #2 wakeup_socket lib/isc/unix/socket.c:897:11 #3 process_ctlfd lib/isc/unix/socket.c:3362:3 #4 process_fds lib/isc/unix/socket.c:3275:10 #5 netthread lib/isc/unix/socket.c:3516:10 Previous write of size 8 at 0x000000000001 by thread T2 (mutexes: write M2): #0 connect #1 isc_socket_connect lib/isc/unix/socket.c:4737:7 #2 resquery_send lib/dns/resolver.c:2892:13 #3 fctx_query lib/dns/resolver.c:2202:12 #4 fctx_try lib/dns/resolver.c:4300:11 #5 resquery_connected lib/dns/resolver.c:3130:4 #6 dispatch lib/isc/task.c:1152:7 #7 run lib/isc/task.c:1344:2 Location is file descriptor 513 created by thread T2 at: #0 connect #1 isc_socket_connect lib/isc/unix/socket.c:4737:7 #2 resquery_send lib/dns/resolver.c:2892:13 #3 fctx_query lib/dns/resolver.c:2202:12 #4 fctx_try lib/dns/resolver.c:4300:11 #5 resquery_connected lib/dns/resolver.c:3130:4 #6 dispatch lib/isc/task.c:1152:7 #7 run lib/isc/task.c:1344:2 Mutex M1 (0x000000000016) created at: #0 pthread_mutex_init #1 isc__mutex_init lib/isc/pthreads/mutex.c:288:8 #2 setup_thread lib/isc/unix/socket.c:3584:3 #3 isc_socketmgr_create2 lib/isc/unix/socket.c:3825:3 #4 create_managers bin/named/main.c:932:11 #5 setup bin/named/main.c:1223:11 #6 main bin/named/main.c:1523:2 Mutex M2 is already destroyed. Thread T1 'isc-socket-1' (running) created by main thread at: #0 pthread_create #1 isc_thread_create lib/isc/pthreads/thread.c:73:8 #2 isc_socketmgr_create2 lib/isc/unix/socket.c:3826:3 #3 create_managers bin/named/main.c:932:11 #4 setup bin/named/main.c:1223:11 #5 main bin/named/main.c:1523:2 Thread T2 (running) created by main thread at: #0 pthread_create #1 isc_thread_create lib/isc/pthreads/thread.c:73:8 #2 isc_taskmgr_create lib/isc/task.c:1434:3 #3 create_managers bin/named/main.c:915:11 #4 setup bin/named/main.c:1223:11 #5 main bin/named/main.c:1523:2 SUMMARY: ThreadSanitizer: data race in epoll_ctl --- diff --git a/lib/isc/unix/socket.c b/lib/isc/unix/socket.c index 570f91870a3..e3e49689e8f 100644 --- a/lib/isc/unix/socket.c +++ b/lib/isc/unix/socket.c @@ -701,7 +701,13 @@ watch_fd(isc__socketthread_t *thread, int fd, int msg) { event.data.fd = fd; op = (oldevents == 0U) ? EPOLL_CTL_ADD : EPOLL_CTL_MOD; + if (thread->fds[fd] != NULL) { + LOCK(&thread->fds[fd]->lock); + } ret = epoll_ctl(thread->epoll_fd, op, fd, &event); + if (thread->fds[fd] != NULL) { + UNLOCK(&thread->fds[fd]->lock); + } if (ret == -1) { if (errno == EEXIST) { UNEXPECTED_ERROR(__FILE__, __LINE__,