Resolve TSAN data race in zone_maintenance

Fix race between zone_maintenance and dns_zone_notifyreceive functions,
zone_maintenance was attempting to read a zone flag calling
DNS_ZONE_FLAG(zone, flag) while dns_zone_notifyreceive was updating
a flag in the same zone calling DNS_ZONE_SETFLAG(zone, ...).

The code reading the flag in zone_maintenance was not protected by the
zone's lock, to avoid a race the zone's lock is now being acquired
before an attempt to read the zone flag is made.
86 jobs for !4868 with 2582-threadsanitizer-data-race-lib-dns-zone-c-10272-7-in-zone_maintenance-v9_11 in 15 minutes and 42 seconds (queued for 8 seconds)
latest detached
Status Job ID Name Coverage
  Precheck
passed #1623552
linux amd64
autoreconf

00:00:22

passed #1623554
linux amd64
clang-format

00:00:15

passed #1623555
linux amd64
coccinelle

00:01:14

failed #1623556
linux amd64
danger

00:00:21

passed #1623553
linux amd64
misc

00:00:21

 
  Build
passed #1623571
linux amd64
clang:asan

00:04:56

passed #1623577
linux amd64
clang:buster:amd64

00:02:31

passed #1623579
amd64 libvirt
clang:freebsd11:amd64

00:02:23

passed #1623580
amd64 libvirt
clang:freebsd12:amd64

00:02:22

passed #1623581
amd64 libvirt
clang:openbsd:amd64

00:04:17

passed #1623573
linux amd64
clang:tsan

00:02:20

passed #1623575
linux amd64
clang:tsan:noatomics

00:02:42

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

00:01:59

passed #1623570
linux amd64
gcc:asan

00:03:54

passed #1623563
linux amd64
gcc:buster:amd64

00:01:44

passed #1623559
linux amd64
gcc:centos6:amd64

00:01:42

passed #1623558
linux i386
gcc:centos6:i386

00:01:35

passed #1623560
linux amd64
gcc:centos7:amd64

00:01:29

passed #1623561
linux amd64
gcc:centos8:amd64

00:02:02

passed #1623567
linux amd64
gcc:fedora33:amd64

00:01:59

passed #1623569
linux amd64
gcc:focal:amd64

00:02:25

passed #1623576
linux amd64
gcc:noatomics

00:02:25

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

00:01:56

passed #1623578
linux amd64
gcc:pkcs11

00:02:07

passed #1623564
linux amd64
gcc:sid:amd64

00:02:14

passed #1623562
linux amd64
gcc:stretch:amd64

00:02:33

passed #1623572
linux amd64
gcc:tsan

00:02:35

passed #1623574
linux amd64
gcc:tsan:noatomics

00:02:00

passed #1623566
linux amd64
gcc:tumbleweed:amd64

00:01:54

passed #1623568
linux amd64
gcc:xenial:amd64

00:02:20

passed #1623583
amd64 windows
msvc:windows:amd64

00:01:30

passed #1623582
linux amd64
nolibtool:sid:amd64

00:02:45

 
  Unit
passed #1623597
linux amd64
unit:clang:asan

00:01:16

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

00:00:32

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

00:01:12

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

00:00:54

passed #1623599
linux amd64
unit:clang:tsan

00:04:28

passed #1623601
linux amd64
unit:clang:tsan:noatomics

00:04:06

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

00:00:48

passed #1623596
linux amd64
unit:gcc:asan

00:01:14

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

00:01:02

passed #1623586
linux amd64
unit:gcc:centos6:amd64

00:00:46

passed #1623585
linux i386
unit:gcc:centos6:i386

00:00:32

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

00:00:38

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

00:00:33

passed #1623593
linux amd64
unit:gcc:fedora33:amd64

00:00:32

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

00:00:36

passed #1623602
linux amd64
unit:gcc:noatomics

00:00:29

passed #1623604
linux amd64
unit:gcc:pkcs11

00:00:41

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

00:00:33

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

00:00:35

passed #1623598
linux amd64
unit:gcc:tsan

00:05:09

passed #1623600
linux amd64
unit:gcc:tsan:noatomics

00:04:59

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

00:00:33

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

00:00:37

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

00:00:47

 
  System
passed #1623621
linux amd64
system:clang:asan

00:09:26

passed #1623627
linux amd64
system:clang:buster:amd64

00:07:25

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

00:08:13

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

00:08:18

passed #1623623
linux amd64
system:clang:tsan

00:11:31

failed #1623625
linux amd64 allowed to fail
system:clang:tsan:noatomics

00:11:14

passed #1623608
linux amd64
system:gcc:alpine3.13:amd64

00:08:06

passed #1623620
linux amd64
system:gcc:asan

00:09:36

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

00:08:19

passed #1623610
linux amd64
system:gcc:centos6:amd64

00:07:27

passed #1623609
linux i386
system:gcc:centos6:i386

00:06:49

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

00:07:28

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

00:07:14

passed #1623617
linux amd64
system:gcc:fedora33:amd64

00:07:11

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

00:07:09

passed #1623626
linux amd64
system:gcc:noatomics

00:07:07

passed #1623628
linux amd64
system:gcc:pkcs11

00:07:51

passed #1623615
linux amd64
system:gcc:sid:amd64

00:07:15

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

00:07:32

passed #1623622
linux amd64
system:gcc:tsan

00:12:13

passed #1623624
linux amd64
system:gcc:tsan:noatomics

00:12:10

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

00:07:17

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

00:07:27

passed #1623631
linux amd64
system:nolibtool:sid:amd64

00:07:32

 
  Docs
passed #1623632
linux amd64
docs

00:00:57

 
  Postcheck
passed #1623636
linux amd64
cppcheck

00:00:58

passed #1623633
linux amd64
flake8

00:00:44

passed #1623637
linux amd64
gcov

00:00:38

74.0%
passed #1623634
linux amd64
pylint

00:00:46

passed #1623635
linux amd64
scan-build

00:09:47

 
Name Stage Failure
failed
system:clang:tsan:noatomics System
Running after_script
Running after script...
$ find bin -name 'tsan.*' -exec python3 util/parse_tsan.py {} \;
Uploading artifacts for failed job
Uploading artifacts...
untracked: found 1437 files

Uploading artifacts as "archive" to coordinator... ok
id=1623625 responseStatus=201 Created token=VxzMivzv
Cleaning up file based variables
ERROR: Job failed: exit code 1
failed
danger Precheck
 * branch            v9_11      -> FETCH_HEAD



Failing the build, there is 1 fail.
Feedback: https://gitlab.isc.org/isc-projects/bind9/merge_requests/4868#note_205469

Cleaning up file based variables
ERROR: Job failed: exit code 1