From 8b7e1235282a9e74efdb031920861381330e69ef Mon Sep 17 00:00:00 2001 From: Artem Boldariev Date: Fri, 2 Dec 2022 10:41:28 +0200 Subject: [PATCH] DoH: Avoid accessing non-atomic listener socket flags when accepting This commit ensures that the non-atomic flags inside a DoH listener socket object (and associated worker) are accessed when doing accept for a connection only from within the context of the dedicated thread, but not other worker threads. The purpose of this commit is to avoid TSAN errors during isc__nmsocket_closing() calls. It is a continuation of 4b5559cd8f41e67bf03e92d9d0338dee9d549b48. --- lib/isc/netmgr/http.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/isc/netmgr/http.c b/lib/isc/netmgr/http.c index bd4a02ed68..7b1d6f7ece 100644 --- a/lib/isc/netmgr/http.c +++ b/lib/isc/netmgr/http.c @@ -2459,7 +2459,9 @@ httplisten_acceptcb(isc_nmhandle_t *handle, isc_result_t result, void *cbarg) { * function gets invoked, so we need to do extra sanity checks to * detect this case. */ - if (isc__nmsocket_closing(handle->sock) || httpserver == NULL) { + if (isc__nm_closing(handle->sock->worker)) { + return (ISC_R_SHUTTINGDOWN); + } else if (isc__nmsocket_closing(handle->sock) || httpserver == NULL) { return (ISC_R_CANCELED); } @@ -2471,9 +2473,7 @@ httplisten_acceptcb(isc_nmhandle_t *handle, isc_result_t result, void *cbarg) { REQUIRE(VALID_NMSOCK(httplistensock)); INSIST(httplistensock == httpserver); - if (isc__nmsocket_closing(httplistensock) || - !atomic_load(&httplistensock->listening)) - { + if (atomic_load(&httplistensock->closing)) { return (ISC_R_CANCELED); }