From df0cc443326d35bb21c37780c1435c3d6c4e8e26 Mon Sep 17 00:00:00 2001 From: Andrew Savinykh <658865+AndrewSav@users.noreply.github.com> Date: Sat, 5 Dec 2026 09:40:30 +1300 Subject: [PATCH 1/3] Wait for unbound to listen before starting the other services _parent only waited for unbound's run script to start, not for unbound to accept connections. On a first start freshclam could run before that, fail to resolve its mirrors and exit, and clamd was then started without a database. It crashed about once a second until a database arrived, and the watchdog stopped it for good at the 20th failure. This failed the default suite on master: clamd had restarted 4 times, and its errors were in mail.err. Wait until 127.0.0.1:53 accepts connections, for about 30 seconds at most, then log a warning and carry on. Nothing changes with DISABLE_DNS_RESOLVER=true. --- rootfs/services/_parent/run | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/rootfs/services/_parent/run b/rootfs/services/_parent/run index 565a462..fe02b2e 100644 --- a/rootfs/services/_parent/run +++ b/rootfs/services/_parent/run @@ -17,6 +17,18 @@ sleep 1 s6-svc -u /services/rsyslogd && s6-svwait -u /services/rsyslogd s6-svc -u /services/unbound && [ "$DISABLE_DNS_RESOLVER" = true ] || s6-svwait -u /services/unbound + +# s6-svwait only waits for the run script to start. Wait until unbound accepts +# connections, or freshclam can fail to resolve its mirrors and clamd is then +# started without a database. +if [ "$DISABLE_DNS_RESOLVER" != true ]; then + for _ in {1..150}; do + nc -z 127.0.0.1 53 && break + sleep 0.2 + done + nc -z 127.0.0.1 53 || logger -p mail.warn "s6-supervise : unbound is not answering after 30 seconds, starting the other services anyway" +fi + s6-svc -u /services/postfix && s6-svwait -u /services/postfix s6-svc -u /services/dovecot s6-svc -u /services/rspamd From 83e3858a5323cab415d970dccb9cc8f42c432a18 Mon Sep 17 00:00:00 2001 From: Andrew Savinykh <658865+AndrewSav@users.noreply.github.com> Date: Sat, 5 Dec 2026 14:35:36 +1300 Subject: [PATCH 2/3] Keep the unbound check out of the container log nc reports each successful connection on stderr, which ends up in the container log twice per start. --- rootfs/services/_parent/run | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rootfs/services/_parent/run b/rootfs/services/_parent/run index fe02b2e..d4fbc6d 100644 --- a/rootfs/services/_parent/run +++ b/rootfs/services/_parent/run @@ -23,10 +23,10 @@ s6-svc -u /services/unbound && [ "$DISABLE_DNS_RESOLVER" = true ] || s6-svwait # started without a database. if [ "$DISABLE_DNS_RESOLVER" != true ]; then for _ in {1..150}; do - nc -z 127.0.0.1 53 && break + nc -z 127.0.0.1 53 2>/dev/null && break sleep 0.2 done - nc -z 127.0.0.1 53 || logger -p mail.warn "s6-supervise : unbound is not answering after 30 seconds, starting the other services anyway" + nc -z 127.0.0.1 53 2>/dev/null || logger -p mail.warn "s6-supervise : unbound is not answering after 30 seconds, starting the other services anyway" fi s6-svc -u /services/postfix && s6-svwait -u /services/postfix From c206970648fd2e94a778418688e4c161a9b9595c Mon Sep 17 00:00:00 2001 From: Andrew Savinykh <658865+AndrewSav@users.noreply.github.com> Date: Sat, 5 Dec 2026 14:35:36 +1300 Subject: [PATCH 3/3] Fix two tests that fail now and then in CI "cron job stderr goes to mail.err" makes current-dbs.txt root-owned so that the job, running as clamav, cannot write it. When the update at startup fails, the file is first created by a job the tests run through su, whose umask is 0002, so it is group-writable and clamav can still write it after the chown. Set its mode as well. The diagnostics added in #111 led to this and are removed. "mail.err does not exist" failed when rspamd's public fuzzy server was slow to answer, which rspamd logs as an error. Ignore that message only; any other line still fails the test. --- test/default.bats | 95 ++++++++++------------------------------------- 1 file changed, 20 insertions(+), 75 deletions(-) diff --git a/test/default.bats b/test/default.bats index f81feea..0c9245f 100644 --- a/test/default.bats +++ b/test/default.bats @@ -1039,10 +1039,17 @@ wait_for_log() { assert_failure } -@test "checking logs: /var/log/mail.err in mailserver_default does not exist" { - run docker exec mailserver_default cat /var/log/mail.err - assert_failure - assert_output --partial 'No such file or directory' +# `rspamc stat`, which the rspamd tests above run, makes rspamd ask its public +# fuzzy server (fuzzy-a.rspamd.com) for its hash counts. When the server does +# not answer within the rule's timeout, rspamd logs an error at mail.err, but +# the statistics come back all the same and those tests check them. A slow +# public server says nothing about this image. A lookup made while scanning a +# message would time out the same way and only leave out the fuzzy symbols; +# no test depends on one. Any other line still fails this test. +@test "checking logs: /var/log/mail.err in mailserver_default does not exist or only has fuzzy timeouts" { + run docker exec mailserver_default /bin/sh -c "[ ! -e /var/log/mail.err ] || ! grep -v 'fuzzy_check_timer_callback: got IO timeout with server' /var/log/mail.err" + assert_success + assert_output '' } # run.sh raises the soft open-files limit to the hard limit, which is what @@ -1055,80 +1062,18 @@ wait_for_log() { # Last on purpose: these make the clamav-unofficial-sigs cron job fail, which # writes to mail.log, mail.warn and mail.err, all checked clean above. # -# The next test fails now and then in CI: the job succeeds and prints nothing, -# but its error never reaches syslog at all (not even mail.log), so it is not -# rsyslog being late. To tell the possible causes apart, it runs the job with -# a logger in front of the real one that keeps a copy of what it is given, -# and on failure writes these to the test output (TAP comments): -# -# - the owner of current-dbs.txt just before and after the job, in case it -# was not root-owned when the job wrote it -# - what the job handed to logger, at each priority, in case logger or -# rsyslog lost it -# - the cron line (its minute) and any update running when the job started, -# in case the container's own hourly job overlapped the test - -SIGS_DIAG=/tmp/sigs-diag -SIGS_DBS=/var/lib/clamav-unofficial-sigs/configs/current-dbs.txt - -# Install the copying logger in $SIGS_DIAG. Each call keeps its arguments and -# input in a file of its own. -sigs_diag_setup() { - docker exec mailserver_default /bin/sh -c "rm -rf $SIGS_DIAG && mkdir -m 1777 $SIGS_DIAG" - docker exec -i mailserver_default /bin/sh -c "cat > $SIGS_DIAG/logger && chmod 755 $SIGS_DIAG/logger" <<'EOF' -#!/bin/sh -f=$(mktemp /tmp/sigs-diag/logger.XXXXXX) -echo "logger $*" > "$f" -tee -a "$f" | /usr/bin/logger "$@" -EOF -} - -# sigs_cron_job, with the copying logger first on the PATH -sigs_cron_job_diag() { - docker exec mailserver_default /bin/sh -c "grep -q '^enable_random=\"no\"' /etc/clamav-unofficial-sigs/user.conf || echo 'enable_random=\"no\"' >> /etc/clamav-unofficial-sigs/user.conf" - docker exec mailserver_default /bin/sh -c "grep -v '^#' /etc/cron.d/clamav-unofficial-sigs | grep . | { read -r m h dom mon dow user cmd; su -s /bin/sh \"\$user\" -c \"PATH=$SIGS_DIAG:\\\$PATH; export PATH; \$cmd\"; }" -} - -sigs_owner() { - docker exec mailserver_default stat -c '%U (inode %i, modified %y)' $SIGS_DBS 2>&1 -} - -sigs_running() { - docker exec mailserver_default /bin/sh -c "ps -eo pid,user,lstart,args | grep '[c]lamav-unofficial-sigs[-a-z]*\.sh' || echo '(none)'" - docker exec mailserver_default ls -l /var/lib/clamav-unofficial-sigs/pid/ 2>&1 || true -} - -# Write lines to the test output as TAP comments -sigs_diag_note() { - sed 's/^/# /' >&3 -} - +# chown alone does not always keep clamav from writing the file. When the +# update at startup fails, the file is first created by a job these tests run +# through su, whose umask makes it writable by the clamav group. @test "checking clamav-unofficial-sigs: cron job stderr goes to mail.err" { - sigs_diag_setup - docker exec mailserver_default chown root $SIGS_DBS - before=$(sigs_owner) - running=$(sigs_running) - started=$(date -u +%T.%N) - run sigs_cron_job_diag - job_status=$status job_output=$output - after=$(sigs_owner) - docker exec mailserver_default chown clamav $SIGS_DBS + docker exec mailserver_default chown root /var/lib/clamav-unofficial-sigs/configs/current-dbs.txt + docker exec mailserver_default chmod 644 /var/lib/clamav-unofficial-sigs/configs/current-dbs.txt + run sigs_cron_job + docker exec mailserver_default chown clamav /var/lib/clamav-unofficial-sigs/configs/current-dbs.txt + assert_success + assert_output '' run wait_for_log 'clamav-unofficial-sigs.*current-dbs.txt: Permission denied' /var/log/mail.err - if [ "$status" -ne 0 ]; then - { - echo "diagnostics: job started at $started UTC, exit status $job_status" - echo "cron line: $(docker exec mailserver_default grep -v '^#' /etc/cron.d/clamav-unofficial-sigs | grep .)" - echo "current-dbs.txt before the job: $before" - echo "current-dbs.txt after the job: $after" - echo "updates running when the job started, and the pid directory:" - echo "$running" - echo "what the job handed to logger:" - docker exec mailserver_default /bin/sh -c "for f in $SIGS_DIAG/logger.*; do [ -e \"\$f\" ] || { echo '(logger was not called)'; break; }; echo \"--- \$f\"; cat \"\$f\"; done" - } | sigs_diag_note - fi assert_success - assert_equal "$job_status" 0 - assert_equal "$job_output" '' } @test "checking clamav-unofficial-sigs: cron job stdout goes to mail.warning" {