Fix lock-order-inversion (potential deadlock) in dns_resolver_createfetch

There's a lock-order-inversion when running `zone_maintenance()` from
the timer while shutting down the server `shutdown_server()`.  This only
happens when the taskmgr scheduling is more relaxed and paralellized,
but the issue is real nevertheless.

The associated ThreadSanitizer warning:

    WARNING: ThreadSanitizer: lock-order-inversion (potential deadlock)
      Cycle in lock order graph: M1 (0x000000000001) => M2 (0x000000000000) => M1

      Mutex M2 acquired here while holding mutex M1 in thread T1:
	#0 pthread_mutex_lock <null>
	#1 dns_view_findzonecut lib/dns/view.c:1326:2
	#2 fctx_create lib/dns/resolver.c:5144:13
	#3 dns_resolver_createfetch lib/dns/resolver.c:10977:12
	#4 zone_refreshkeys lib/dns/zone.c:10830:13
	#5 zone_maintenance lib/dns/zone.c:11065:5
	#6 zone_timer lib/dns/zone.c:14652:2
	#7 task_run lib/isc/task.c:857:5
	#8 isc_task_run lib/isc/task.c:944:10
	#9 isc__nm_async_task lib/isc/netmgr/netmgr.c:730:24
	#10 process_netievent lib/isc/netmgr/netmgr.c
	#11 process_queue lib/isc/netmgr/netmgr.c:885:8
	#12 process_tasks_queue lib/isc/netmgr/netmgr.c:756:10
	#13 process_queues lib/isc/netmgr/netmgr.c:772:7
	#14 async_cb lib/isc/netmgr/netmgr.c:671:2
	#15 uv__async_io /home/ondrej/Projects/tsan/libuv/src/unix/async.c:163:5
	#16 uv__io_poll /home/ondrej/Projects/tsan/libuv/src/unix/linux-core.c:462:11
	#17 uv_run /home/ondrej/Projects/tsan/libuv/src/unix/core.c:392:5
	#18 nm_thread lib/isc/netmgr/netmgr.c:597:11
	#19 isc__trampoline_run lib/isc/trampoline.c:184:11

      Mutex M1 previously acquired by the same thread here:
	#0 pthread_mutex_lock <null>
	#1 zone_refreshkeys lib/dns/zone.c:10717:2
	#2 zone_maintenance lib/dns/zone.c:11065:5
	#3 zone_timer lib/dns/zone.c:14652:2
	#4 task_run lib/isc/task.c:857:5
	#5 isc_task_run lib/isc/task.c:944:10
	#6 isc__nm_async_task lib/isc/netmgr/netmgr.c:730:24
	#7 process_netievent lib/isc/netmgr/netmgr.c
	#8 process_queue lib/isc/netmgr/netmgr.c:885:8
	#9 process_tasks_queue lib/isc/netmgr/netmgr.c:756:10
	#10 process_queues lib/isc/netmgr/netmgr.c:772:7
	#11 async_cb lib/isc/netmgr/netmgr.c:671:2
	#12 uv__async_io /home/ondrej/Projects/tsan/libuv/src/unix/async.c:163:5
	#13 uv__io_poll /home/ondrej/Projects/tsan/libuv/src/unix/linux-core.c:462:11
	#14 uv_run /home/ondrej/Projects/tsan/libuv/src/unix/core.c:392:5
	#15 nm_thread lib/isc/netmgr/netmgr.c:597:11
	#16 isc__trampoline_run lib/isc/trampoline.c:184:11

      Mutex M1 acquired here while holding mutex M2 in thread T2:
	#0 pthread_mutex_lock <null>
	#1 dns_zone_flush lib/dns/zone.c:11443:2
	#2 view_flushanddetach lib/dns/view.c:657:5
	#3 dns_view_flushanddetach lib/dns/view.c:690:2
	#4 shutdown_server bin/named/server.c:10056:4
	#5 task_run lib/isc/task.c:857:5
	#6 isc_task_run lib/isc/task.c:944:10
	#7 isc__nm_async_task lib/isc/netmgr/netmgr.c:730:24
	#8 process_netievent lib/isc/netmgr/netmgr.c
	#9 process_queue lib/isc/netmgr/netmgr.c:885:8
	#10 process_tasks_queue lib/isc/netmgr/netmgr.c:756:10
	#11 process_queues lib/isc/netmgr/netmgr.c:772:7
	#12 async_cb lib/isc/netmgr/netmgr.c:671:2
	#13 uv__async_io /home/ondrej/Projects/tsan/libuv/src/unix/async.c:163:5
	#14 uv__io_poll /home/ondrej/Projects/tsan/libuv/src/unix/linux-core.c:462:11
	#15 uv_run /home/ondrej/Projects/tsan/libuv/src/unix/core.c:392:5
	#16 nm_thread lib/isc/netmgr/netmgr.c:597:11
	#17 isc__trampoline_run lib/isc/trampoline.c:184:11

      Mutex M2 previously acquired by the same thread here:
	#0 pthread_mutex_lock <null>
	#1 view_flushanddetach lib/dns/view.c:645:3
	#2 dns_view_flushanddetach lib/dns/view.c:690:2
	#3 shutdown_server bin/named/server.c:10056:4
	#4 task_run lib/isc/task.c:857:5
	#5 isc_task_run lib/isc/task.c:944:10
	#6 isc__nm_async_task lib/isc/netmgr/netmgr.c:730:24
	#7 process_netievent lib/isc/netmgr/netmgr.c
	#8 process_queue lib/isc/netmgr/netmgr.c:885:8
	#9 process_tasks_queue lib/isc/netmgr/netmgr.c:756:10
	#10 process_queues lib/isc/netmgr/netmgr.c:772:7
	#11 async_cb lib/isc/netmgr/netmgr.c:671:2
	#12 uv__async_io /home/ondrej/Projects/tsan/libuv/src/unix/async.c:163:5
	#13 uv__io_poll /home/ondrej/Projects/tsan/libuv/src/unix/linux-core.c:462:11
	#14 uv_run /home/ondrej/Projects/tsan/libuv/src/unix/core.c:392:5
	#15 nm_thread lib/isc/netmgr/netmgr.c:597:11
	#16 isc__trampoline_run lib/isc/trampoline.c:184:11

      Thread T2 (running) created by main thread at:
	#0 pthread_create <null>
	#1 isc_thread_create lib/isc/pthreads/thread.c:79:8
	#2 isc_nm_start lib/isc/netmgr/netmgr.c:303:3
	#3 create_managers bin/named/main.c:957:15
	#4 setup bin/named/main.c:1267:11
	#5 main bin/named/main.c:1558:2

      Thread T2 (running) created by main thread at:
	#0 pthread_create <null>
	#1 isc_thread_create lib/isc/pthreads/thread.c:79:8
	#2 isc_nm_start lib/isc/netmgr/netmgr.c:303:3
	#3 create_managers bin/named/main.c:957:15
	#4 setup bin/named/main.c:1267:11
	#5 main bin/named/main.c:1558:2

    SUMMARY: ThreadSanitizer: lock-order-inversion (potential deadlock) in __interceptor_pthread_mutex_lock

(cherry picked from commit 25d27851)
78 jobs for !4920 with 2637-threadsanitizer-lock-order-inversion-potential-deadlock-in-zone_refreshkeys-v9_16 in 25 minutes and 23 seconds (queued for 26 seconds)
latest detached
Status Job ID Name Coverage
  Precheck
passed #1651365
amd64 linux
autoreconf

00:00:15

passed #1651369
amd64 linux
clang-format

00:00:18

passed #1651371
amd64 linux
coccinelle

00:03:22

passed #1651373
amd64 linux
danger

00:00:15

passed #1651366
amd64 linux
misc

00:00:14

 
  Build
passed #1651399
amd64 linux
clang:asan

00:03:57

passed #1651407
amd64 linux
clang:buster:amd64

00:01:57

passed #1651413
amd64 libvirt
clang:freebsd11:amd64

00:01:46

passed #1651414
amd64 libvirt
clang:freebsd12:amd64

00:01:37

passed #1651417
amd64 libvirt
clang:openbsd:amd64

00:03:54

passed #1651403
amd64 linux
clang:tsan

00:02:10

passed #1651375
amd64 linux
gcc:alpine3.13:amd64

00:01:46

passed #1651397
amd64 linux
gcc:asan

00:03:13

passed #1651383
amd64 linux
gcc:buster:amd64

00:01:35

passed #1651377
amd64 linux
gcc:centos7:amd64

00:01:24

passed #1651379
amd64 linux
gcc:centos8:amd64

00:01:37

passed #1651395
amd64 linux
gcc:focal:amd64

00:01:35

passed #1651405
amd64 linux
gcc:mutexatomics

00:01:34

passed #1651387
amd64 linux
gcc:out-of-tree

00:01:26

passed #1651385
amd64 linux
gcc:sid:amd64

00:01:56

passed #1651389
i386 linux
gcc:sid:i386

00:01:35

passed #1651409
amd64 linux
gcc:softhsm2.4

00:01:38

passed #1651411
amd64 linux
gcc:softhsm2.6

00:01:33

passed #1651381
amd64 linux
gcc:stretch:amd64

00:01:47

passed #1651401
amd64 linux
gcc:tsan

00:01:52

passed #1651390
amd64 linux
gcc:tumbleweed:amd64

00:01:29

passed #1651393
amd64 linux
gcc:xenial:amd64

00:01:42

passed #1651420
amd64 windows
msvc:windows:amd64

00:01:05

passed #1651418
amd64 linux
nolibtool:sid:amd64

00:02:02

 
  Unit
passed #1651444
amd64 linux
unit:clang:asan

00:01:19

passed #1651452
amd64 linux
unit:clang:buster:amd64

00:00:35

passed #1651457
amd64 libvirt
unit:clang:freebsd11:amd64

00:00:58

passed #1651519
libvirt amd64
unit:clang:freebsd12:amd64

00:01:04

passed #1651448
amd64 linux
unit:clang:tsan

00:01:37

passed #1651423
amd64 linux
unit:gcc:alpine3.13:amd64

00:01:01

passed #1651442
amd64 linux
unit:gcc:asan

00:01:18

passed #1651430
amd64 linux
unit:gcc:buster:amd64

00:00:59

passed #1651425
amd64 linux
unit:gcc:centos7:amd64

00:00:40

passed #1651427
amd64 linux
unit:gcc:centos8:amd64

00:00:37

passed #1651440
amd64 linux
unit:gcc:focal:amd64

00:00:37

passed #1651449
amd64 linux
unit:gcc:mutexatomics

00:00:41

passed #1651432
amd64 linux
unit:gcc:sid:amd64

00:00:37

passed #1651434
i386 linux
unit:gcc:sid:i386

00:00:47

passed #1651454
amd64 linux
unit:gcc:softhsm2.4

00:00:37

passed #1651456
amd64 linux
unit:gcc:softhsm2.6

00:00:40

passed #1651428
amd64 linux
unit:gcc:stretch:amd64

00:00:36

passed #1651446
amd64 linux
unit:gcc:tsan

00:01:47

passed #1651436
amd64 linux
unit:gcc:tumbleweed:amd64

00:00:39

passed #1651438
amd64 linux
unit:gcc:xenial:amd64

00:00:38

passed #1651462
amd64 linux
unit:nolibtool:sid:amd64

00:00:47

failed #1651459
amd64 libvirt
unit:clang:freebsd12:amd64

00:05:59

 
  System
canceled #1651486
amd64 linux
system:clang:asan

00:12:33

canceled #1651494
amd64 linux
system:clang:buster:amd64

00:09:24

passed #1651500
amd64 libvirt
system:clang:freebsd11:amd64

00:11:16

passed #1651501
amd64 libvirt
system:clang:freebsd12:amd64

00:11:07

canceled #1651490
amd64 linux
system:clang:tsan

00:10:27

failed #1651464
amd64 linux
system:gcc:alpine3.13:amd64

00:12:04

canceled #1651484
amd64 linux
system:gcc:asan

00:12:42

passed #1651471
amd64 linux
system:gcc:buster:amd64

00:12:47

passed #1651466
amd64 linux
system:gcc:centos7:amd64

00:11:34

passed #1651468
amd64 linux
system:gcc:centos8:amd64

00:11:48

passed #1651482
amd64 linux
system:gcc:focal:amd64

00:11:52

canceled #1651492
amd64 linux
system:gcc:mutexatomics

00:10:25

failed #1651474
amd64 linux
system:gcc:sid:amd64

00:12:01

passed #1651476
i386 linux
system:gcc:sid:i386

00:10:15

canceled #1651496
amd64 linux
system:gcc:softhsm2.4

00:08:45

canceled #1651498
amd64 linux
system:gcc:softhsm2.6

00:04:16

passed #1651470
amd64 linux
system:gcc:stretch:amd64

00:11:29

canceled #1651488
amd64 linux
system:gcc:tsan

00:10:47

passed #1651477
amd64 linux
system:gcc:tumbleweed:amd64

00:11:44

passed #1651479
amd64 linux
system:gcc:xenial:amd64

00:11:32

canceled #1651503
amd64 linux
system:nolibtool:sid:amd64

00:03:12

 
  Docs
passed #1651505
amd64 linux
docs

00:02:09

 
  Postcheck
passed #1651512
amd64 linux
cppcheck

00:00:21

passed #1651507
amd64 linux
flake8

00:00:17

passed #1651513
amd64 linux
gcov

00:00:33

75.0%
passed #1651509
amd64 linux
pylint

00:00:21

canceled #1651511
amd64 linux
scan-build

00:02:41

 
Name Stage Failure
failed
system:gcc:sid:amd64 System
I:The following system tests failed:
I: inline
make: *** [Makefile:502: test] Error 1
Uploading artifacts for failed job
Uploading artifacts...
untracked: found 2319 files

Uploading artifacts as "archive" to coordinator... ok
id=1651474 responseStatus=201 Created token=4L2wTLxq
Cleaning up file based variables
ERROR: Job failed: exit code 1
failed
system:gcc:alpine3.13:amd64 System
I:The following system tests failed:
I: serve-stale
make: *** [Makefile:502: test] Error 1
Uploading artifacts for failed job
Uploading artifacts...
untracked: found 1633 files

Uploading artifacts as "archive" to coordinator... ok
id=1651464 responseStatus=201 Created token=xPpa-Pkd
Cleaning up file based variables
ERROR: Job failed: exit code 1