From 15883a95f26e690a179145e224d3a5d7d3d21cdd Mon Sep 17 00:00:00 2001 From: Jiwoo Park Date: Sat, 9 Nov 2024 21:45:35 +0900 Subject: [PATCH] Silence TSAN, lock before checking `ares_event_thread::isup` (#915) TSAN is warning about a thread concurrency issue that doesn't actually matter if the operation isn't atomic as its an optimization in this code path to skip timeout processing if we're shutting down due to ares_destroy(). Fix By: Jiwoo Park (@jimmy-park) --- src/lib/event/ares_event_thread.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib/event/ares_event_thread.c b/src/lib/event/ares_event_thread.c index 8b332e9b..beaa5e10 100644 --- a/src/lib/event/ares_event_thread.c +++ b/src/lib/event/ares_event_thread.c @@ -326,13 +326,15 @@ static void *ares_event_thread(void *arg) e->ev_sys->wait(e, timeout_ms); + /* Relock before we loop again */ + ares_thread_mutex_lock(e->mutex); + /* Each iteration should do timeout processing */ if (e->isup) { + ares_thread_mutex_unlock(e->mutex); ares_process_fd(e->channel, ARES_SOCKET_BAD, ARES_SOCKET_BAD); + ares_thread_mutex_lock(e->mutex); } - - /* Relock before we loop again */ - ares__thread_mutex_lock(e->mutex); } /* Lets cleanup while we're in the thread itself */