ThreadSanitizer: lock-order-inversion (potential deadlock) in __interceptor_pthread_mutex_lock in resolver.c (9.18)
The added code coverage in !7977 (merged) has uncovered a preexisting issue reported by TSAN. Here's the report (line numbers correspond to commit 8a9ce5a7):
WARNING: ThreadSanitizer: lock-order-inversion (potential deadlock) (pid=107066)
Cycle in lock order graph: M0 (0x7b9400028a28) => M1 (0x7b4800015490) => M0
Mutex M1 acquired here while holding mutex M0 in thread T1:
#0 pthread_mutex_lock <null> (named+0x67a7b) (BuildId: 0841b8f64e42f843435425f538d0d69cc808e37a)
#1 fctx_sendevents /builds/isc-projects/bind9/lib/dns/resolver.c:1801:3 (libdns-9.18.16-dev.so+0x1867fe) (BuildId: 184ff5c2c676a86ff8d2823dffbae7684b323bb6)
#2 fctx__done_detach /builds/isc-projects/bind9/lib/dns/resolver.c:1893:2 (libdns-9.18.16-dev.so+0x183e7b) (BuildId: 184ff5c2c676a86ff8d2823dffbae7684b323bb6)
#3 rctx_done /builds/isc-projects/bind9/lib/dns/resolver.c (libdns-9.18.16-dev.so+0x1900cd) (BuildId: 184ff5c2c676a86ff8d2823dffbae7684b323bb6)
#4 resquery_response /builds/isc-projects/bind9/lib/dns/resolver.c (libdns-9.18.16-dev.so+0x18e1fb) (BuildId: 184ff5c2c676a86ff8d2823dffbae7684b323bb6)
#5 udp_recv /builds/isc-projects/bind9/lib/dns/dispatch.c:638:3 (libdns-9.18.16-dev.so+0x67bf7) (BuildId: 184ff5c2c676a86ff8d2823dffbae7684b323bb6)
#6 isc__nm_async_readcb /builds/isc-projects/bind9/lib/isc/netmgr/netmgr.c:2885:2 (libisc-9.18.16-dev.so+0x2c913) (BuildId: 4692f4fd1f4b6179023dbe9c8b9ecd8e2ed763f4)
#7 isc__nm_readcb /builds/isc-projects/bind9/lib/isc/netmgr/netmgr.c:2858:3 (libisc-9.18.16-dev.so+0x2a532) (BuildId: 4692f4fd1f4b6179023dbe9c8b9ecd8e2ed763f4)
#8 udp_recv_cb /builds/isc-projects/bind9/lib/isc/netmgr/udp.c:650:2 (libisc-9.18.16-dev.so+0x4265e) (BuildId: 4692f4fd1f4b6179023dbe9c8b9ecd8e2ed763f4)
#9 isc__nm_udp_read_cb /builds/isc-projects/bind9/lib/isc/netmgr/udp.c:1057:2 (libisc-9.18.16-dev.so+0x43fbb) (BuildId: 4692f4fd1f4b6179023dbe9c8b9ecd8e2ed763f4)
#10 uv__udp_recvmsg /usr/src/libuv-v1.44.1/src/unix/udp.c:303:7 (libuv.so.1+0x264ef) (BuildId: 120c450d14885aa5308bc95c4ea77de2c2b1cc36)
#11 isc__trampoline_run /builds/isc-projects/bind9/lib/isc/trampoline.c:189:11 (libisc-9.18.16-dev.so+0x81127) (BuildId: 4692f4fd1f4b6179023dbe9c8b9ecd8e2ed763f4)
Mutex M0 previously acquired by the same thread here:
#0 pthread_mutex_lock <null> (named+0x67a7b) (BuildId: 0841b8f64e42f843435425f538d0d69cc808e37a)
#1 fctx__done_detach /builds/isc-projects/bind9/lib/dns/resolver.c:1891:2 (libdns-9.18.16-dev.so+0x183e4d) (BuildId: 184ff5c2c676a86ff8d2823dffbae7684b323bb6)
#2 rctx_done /builds/isc-projects/bind9/lib/dns/resolver.c (libdns-9.18.16-dev.so+0x1900cd) (BuildId: 184ff5c2c676a86ff8d2823dffbae7684b323bb6)
#3 resquery_response /builds/isc-projects/bind9/lib/dns/resolver.c (libdns-9.18.16-dev.so+0x18e1fb) (BuildId: 184ff5c2c676a86ff8d2823dffbae7684b323bb6)
#4 udp_recv /builds/isc-projects/bind9/lib/dns/dispatch.c:638:3 (libdns-9.18.16-dev.so+0x67bf7) (BuildId: 184ff5c2c676a86ff8d2823dffbae7684b323bb6)
#5 isc__nm_async_readcb /builds/isc-projects/bind9/lib/isc/netmgr/netmgr.c:2885:2 (libisc-9.18.16-dev.so+0x2c913) (BuildId: 4692f4fd1f4b6179023dbe9c8b9ecd8e2ed763f4)
#6 isc__nm_readcb /builds/isc-projects/bind9/lib/isc/netmgr/netmgr.c:2858:3 (libisc-9.18.16-dev.so+0x2a532) (BuildId: 4692f4fd1f4b6179023dbe9c8b9ecd8e2ed763f4)
#7 udp_recv_cb /builds/isc-projects/bind9/lib/isc/netmgr/udp.c:650:2 (libisc-9.18.16-dev.so+0x4265e) (BuildId: 4692f4fd1f4b6179023dbe9c8b9ecd8e2ed763f4)
#8 isc__nm_udp_read_cb /builds/isc-projects/bind9/lib/isc/netmgr/udp.c:1057:2 (libisc-9.18.16-dev.so+0x43fbb) (BuildId: 4692f4fd1f4b6179023dbe9c8b9ecd8e2ed763f4)
#9 uv__udp_recvmsg /usr/src/libuv-v1.44.1/src/unix/udp.c:303:7 (libuv.so.1+0x264ef) (BuildId: 120c450d14885aa5308bc95c4ea77de2c2b1cc36)
#10 isc__trampoline_run /builds/isc-projects/bind9/lib/isc/trampoline.c:189:11 (libisc-9.18.16-dev.so+0x81127) (BuildId: 4692f4fd1f4b6179023dbe9c8b9ecd8e2ed763f4)
Mutex M0 acquired here while holding mutex M1 in thread T1:
#0 pthread_mutex_lock <null> (named+0x67a7b) (BuildId: 0841b8f64e42f843435425f538d0d69cc808e37a)
#1 dns_resolver_shutdown /builds/isc-projects/bind9/lib/dns/resolver.c:10661:4 (libdns-9.18.16-dev.so+0x17d743) (BuildId: 184ff5c2c676a86ff8d2823dffbae7684b323bb6)
#2 view_flushanddetach /builds/isc-projects/bind9/lib/dns/view.c:650:4 (libdns-9.18.16-dev.so+0x1d7b5d) (BuildId: 184ff5c2c676a86ff8d2823dffbae7684b323bb6)
#3 dns_view_flushanddetach /builds/isc-projects/bind9/lib/dns/view.c:711:2 (libdns-9.18.16-dev.so+0x1d79de) (BuildId: 184ff5c2c676a86ff8d2823dffbae7684b323bb6)
#4 shutdown_server /builds/isc-projects/bind9/bin/named/server.c:10153:4 (named+0xfe7c4) (BuildId: 0841b8f64e42f843435425f538d0d69cc808e37a)
#5 task_run /builds/isc-projects/bind9/lib/isc/task.c:815:5 (libisc-9.18.16-dev.so+0x75935) (BuildId: 4692f4fd1f4b6179023dbe9c8b9ecd8e2ed763f4)
#6 isc_task_run /builds/isc-projects/bind9/lib/isc/task.c:896:10 (libisc-9.18.16-dev.so+0x75935)
#7 isc__nm_async_task /builds/isc-projects/bind9/lib/isc/netmgr/netmgr.c:848:11 (libisc-9.18.16-dev.so+0x2ebe7) (BuildId: 4692f4fd1f4b6179023dbe9c8b9ecd8e2ed763f4)
#8 process_netievent /builds/isc-projects/bind9/lib/isc/netmgr/netmgr.c (libisc-9.18.16-dev.so+0x26adc) (BuildId: 4692f4fd1f4b6179023dbe9c8b9ecd8e2ed763f4)
#9 process_queue /builds/isc-projects/bind9/lib/isc/netmgr/netmgr.c:1013:8 (libisc-9.18.16-dev.so+0x2e9f7) (BuildId: 4692f4fd1f4b6179023dbe9c8b9ecd8e2ed763f4)
#10 process_all_queues /builds/isc-projects/bind9/lib/isc/netmgr/netmgr.c:767:25 (libisc-9.18.16-dev.so+0x20306) (BuildId: 4692f4fd1f4b6179023dbe9c8b9ecd8e2ed763f4)
#11 async_cb /builds/isc-projects/bind9/lib/isc/netmgr/netmgr.c:796:6 (libisc-9.18.16-dev.so+0x20306)
#12 uv__async_io /usr/src/libuv-v1.44.1/src/unix/async.c:163:5 (libuv.so.1+0x10e92) (BuildId: 120c450d14885aa5308bc95c4ea77de2c2b1cc36)
#13 isc__trampoline_run /builds/isc-projects/bind9/lib/isc/trampoline.c:189:11 (libisc-9.18.16-dev.so+0x81127) (BuildId: 4692f4fd1f4b6179023dbe9c8b9ecd8e2ed763f4)
Mutex M1 previously acquired by the same thread here:
#0 pthread_mutex_lock <null> (named+0x67a7b) (BuildId: 0841b8f64e42f843435425f538d0d69cc808e37a)
#1 dns_resolver_shutdown /builds/isc-projects/bind9/lib/dns/resolver.c:10656:2 (libdns-9.18.16-dev.so+0x17d676) (BuildId: 184ff5c2c676a86ff8d2823dffbae7684b323bb6)
#2 view_flushanddetach /builds/isc-projects/bind9/lib/dns/view.c:650:4 (libdns-9.18.16-dev.so+0x1d7b5d) (BuildId: 184ff5c2c676a86ff8d2823dffbae7684b323bb6)
#3 dns_view_flushanddetach /builds/isc-projects/bind9/lib/dns/view.c:711:2 (libdns-9.18.16-dev.so+0x1d79de) (BuildId: 184ff5c2c676a86ff8d2823dffbae7684b323bb6)
#4 shutdown_server /builds/isc-projects/bind9/bin/named/server.c:10153:4 (named+0xfe7c4) (BuildId: 0841b8f64e42f843435425f538d0d69cc808e37a)
#5 task_run /builds/isc-projects/bind9/lib/isc/task.c:815:5 (libisc-9.18.16-dev.so+0x75935) (BuildId: 4692f4fd1f4b6179023dbe9c8b9ecd8e2ed763f4)
#6 isc_task_run /builds/isc-projects/bind9/lib/isc/task.c:896:10 (libisc-9.18.16-dev.so+0x75935)
#7 isc__nm_async_task /builds/isc-projects/bind9/lib/isc/netmgr/netmgr.c:848:11 (libisc-9.18.16-dev.so+0x2ebe7) (BuildId: 4692f4fd1f4b6179023dbe9c8b9ecd8e2ed763f4)
#8 process_netievent /builds/isc-projects/bind9/lib/isc/netmgr/netmgr.c (libisc-9.18.16-dev.so+0x26adc) (BuildId: 4692f4fd1f4b6179023dbe9c8b9ecd8e2ed763f4)
#9 process_queue /builds/isc-projects/bind9/lib/isc/netmgr/netmgr.c:1013:8 (libisc-9.18.16-dev.so+0x2e9f7) (BuildId: 4692f4fd1f4b6179023dbe9c8b9ecd8e2ed763f4)
#10 process_all_queues /builds/isc-projects/bind9/lib/isc/netmgr/netmgr.c:767:25 (libisc-9.18.16-dev.so+0x20306) (BuildId: 4692f4fd1f4b6179023dbe9c8b9ecd8e2ed763f4)
#11 async_cb /builds/isc-projects/bind9/lib/isc/netmgr/netmgr.c:796:6 (libisc-9.18.16-dev.so+0x20306)
#12 uv__async_io /usr/src/libuv-v1.44.1/src/unix/async.c:163:5 (libuv.so.1+0x10e92) (BuildId: 120c450d14885aa5308bc95c4ea77de2c2b1cc36)
#13 isc__trampoline_run /builds/isc-projects/bind9/lib/isc/trampoline.c:189:11 (libisc-9.18.16-dev.so+0x81127) (BuildId: 4692f4fd1f4b6179023dbe9c8b9ecd8e2ed763f4)
Thread T1 'isc-net-0000' (tid=107081, running) created by main thread at:
#0 pthread_create <null> (named+0x65deb) (BuildId: 0841b8f64e42f843435425f538d0d69cc808e37a)
#1 isc_thread_create /builds/isc-projects/bind9/lib/isc/thread.c:73:8 (libisc-9.18.16-dev.so+0x7834a) (BuildId: 4692f4fd1f4b6179023dbe9c8b9ecd8e2ed763f4)
#2 isc__netmgr_create /builds/isc-projects/bind9/lib/isc/netmgr/netmgr.c:311:3 (libisc-9.18.16-dev.so+0x1fff0) (BuildId: 4692f4fd1f4b6179023dbe9c8b9ecd8e2ed763f4)
#3 isc_managers_create /builds/isc-projects/bind9/lib/isc/managers.c:31:2 (libisc-9.18.16-dev.so+0x5d40c) (BuildId: 4692f4fd1f4b6179023dbe9c8b9ecd8e2ed763f4)
#4 create_managers /builds/isc-projects/bind9/bin/named/main.c:1038:11 (named+0xf9fb8) (BuildId: 0841b8f64e42f843435425f538d0d69cc808e37a)
#5 setup /builds/isc-projects/bind9/bin/named/main.c:1309:11 (named+0xf9fb8)
#6 main /builds/isc-projects/bind9/bin/named/main.c:1587:2 (named+0xf9fb8)
SUMMARY: ThreadSanitizer: lock-order-inversion (potential deadlock) (/builds/isc-projects/bind9/bin/named/.libs/named+0x67a7b) (BuildId: 0841b8f64e42f843435425f538d0d69cc808e37a) in __interceptor_pthread_mutex_lock
==================
ThreadSanitizer: reported 1 warnings
If possible, this needs to be addressed in the June releases, so that the backport MR !7977 (merged) can pass the CI and get merged.