]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Wait until fstrm_capture is ready
authorMichał Kępień <michal@isc.org>
Mon, 7 Aug 2023 09:26:58 +0000 (11:26 +0200)
committerMichał Kępień <michal@isc.org>
Mon, 7 Aug 2023 12:01:51 +0000 (14:01 +0200)
The fstrm_capture utility is started in the background during the
"dnstap" system test.  Consequently, "rndc dnstap-reopen" and similar
commands may be executed before fstrm_capture starts listening on the
Unix domain socket it is configured to receive dnstap data on.  This
results in the dnstap data sent to that socket in the meantime to be
lost; while the fstrm writer thread is able to recover from such a
scenario within a couple of seconds (by reopening the configured dnstap
destination itself), only one write attempt is made for data
successfully queued to the writer thread, so dnstap frames can still be
lost in the process.  This may happen during the "dnstap" system test,
leading to the dnstap output file being empty, which in turn causes the
test to fail.

Fix by waiting until fstrm_capture starts listening on the Unix domain
socket it is configured to use before asking named to reopen the
configured dnstap destination.  Since various fstrm_capture versions log
different messages when the listening socket is set up, wait for a
common string that works for all fstrm_capture versions released to
date.  Add a few extra debug messages indicating test progress and make
the test fail if the expected fstrm_capture log message is not generated
within 10 seconds.

(cherry picked from commit 26d3d97f12db29dbad5bcdf7f698af0498c77e02)

bin/tests/system/dnstap/tests.sh

index 0eb6aee2a4024028ad50bff7690e353166382438..5ed8e7341c854bc67d7999f2f48fb150dd2a975b 100644 (file)
@@ -77,9 +77,14 @@ mv ns1/dnstap.out ns1/dnstap.out.save
 mv ns2/dnstap.out ns2/dnstap.out.save
 
 if [ -n "$FSTRM_CAPTURE" ] ; then
+       ret=0
+       echo_i "starting fstrm_capture"
        $FSTRM_CAPTURE -t protobuf:dnstap.Dnstap -u ns4/dnstap.out \
                -w dnstap.out > fstrm_capture.out.1 2>&1 &
        fstrm_capture_pid=$!
+       wait_for_log 10 "socket path ns4/dnstap.out" fstrm_capture.out.1 || ret=1
+       if [ $ret != 0 ]; then echo_i "failed"; fi
+       status=`expr $status + $ret`
 fi
 
 $RNDCCMD -s 10.53.0.1 dnstap-reopen | sed 's/^/ns1 /' | cat_i
@@ -568,7 +573,7 @@ EOF
                ret=1
        }
        if [ $ret != 0 ]; then echo_i "failed"; fi
-       status=$((status + ret))
+       status=`expr $status + $ret`
        kill $fstrm_capture_pid
        wait
        udp4=`$DNSTAPREAD dnstap.out | grep "UDP " | wc -l`
@@ -672,10 +677,14 @@ EOF
 
        mv dnstap.out dnstap.out.save
 
+       echo_i "restarting fstrm_capture"
        $FSTRM_CAPTURE -t protobuf:dnstap.Dnstap -u ns4/dnstap.out \
                -w dnstap.out > fstrm_capture.out.2 2>&1 &
        fstrm_capture_pid=$!
-       sleep 1
+       wait_for_log 10 "socket path ns4/dnstap.out" fstrm_capture.out.2 || {
+               echo_i "failed"
+               ret=1
+       }
        $RNDCCMD -s 10.53.0.4 dnstap -reopen | sed 's/^/ns4 /' | cat_i
        $DIG $DIGOPTS @10.53.0.4 a.example > dig.out