Skip to content

Fix dns startup race - #113

Open
AndrewSav wants to merge 3 commits into
mailserver2:masterfrom
AndrewSav:fix-dns-startup-race
Open

AndrewSav wants to merge 3 commits into
mailserver2:masterfrom
AndrewSav:fix-dns-startup-race

Conversation

@AndrewSav

Copy link
Copy Markdown
Collaborator

Description

Note

TLDR: More races fixes.

  • What is the current behavior (you can also link to an open issue here) ?

    1. Startup race. Run 47417854223 (master, cf6c344) failed two default tests: clamd had restarted 4 times, and its errors were in mail.err. The container log shows why:

    Time Event
    20:23:34.687 freshclam starts
    34.716 to 34.786 every mirror fails with Could not resolve hostname
    34.786 unbound's run script logs that it is spawning unbound
    34.801 clamd starts without a database and exits, then again about once a second
    38.866 the fifth start finds a database and stays up

    _parent/run waits for unbound with s6-svwait -u, which only waits for its run script to start, not for unbound to accept connections.

    This is not only a test problem. s6 stops clamd for good after 20 failures. With unbound delayed by 3 seconds, clamd was still down after DNS had come up.

    2. cron job stderr goes to mail.err. This is the failure Report why the mail.err cron test fails when it does #111 added diagnostics for, and they caught it in this run on my fork. The test makes current-dbs.txt root-owned so that the job, running as clamav, cannot write it. The report shows the job did write it, and handed nothing to logger:

    • The update at startup had ended after 1.4 seconds. When that update fails, it does not create the file.
    • The file is then created by the first cron job the tests run. They run it through su, which gives clamav a umask of 0002 (0022 at startup), so the file is writable by the clamav group.
    • chown root does not change the group, so clamav can still write the file.

    I reproduced this by making only the startup update's downloads fail. Why that update failed in CI is not in the log, so I don't know.

    3. mail.err does not exist. In the same run on my fork, rspamd logged an error because fuzzy-a.rspamd.com, a public server, did not answer in time. Any line in mail.err fails the test.

    No mail was being scanned at the time. The error was logged while checking rspamd: 7 messages with action no action ran rspamc stat. That test took 4.3 seconds, about 0.3 seconds in the other runs. I checked locally that rspamc stat makes rspamd's controller query the fuzzy server, for its hash counts. The rule waits 2 seconds and retries once, which matches the 4.3 seconds. The statistics still came back, and that test and the other rspamc stat tests passed.

  • What is the new behavior (if this is a feature change) ?

    • _parent/run waits until 127.0.0.1:53 accepts connections before it starts postfix and everything after it. The wait is skipped with DISABLE_DNS_RESOLVER=true. After about 30 seconds it logs a warning and carries on, as before this change.
    • The cron test also sets the file's mode to 644. The Report why the mail.err cron test fails when it does #111 diagnostics are removed.
    • The default suite's mail.err test ignores that one rspamd message, and a comment in the test says why. The test is still useful: any other line fails it.
      • The message comes from a public server being slow, not from this image, and the statistics it delays are still checked by the rspamd tests.
      • A timeout during a mail scan would only mean no fuzzy symbols for that message. None of the test messages depend on one: the spam test uses GTUBE.
      • The other suites keep the strict check.

    Not covered. If unbound never comes up, or the first download fails for another reason, clamd is still started without a database. Stopping the container instead would be a change for the whole image, since no failed service stops it today. Stop the container when a service it needs cannot run AndrewSav/mailserver#2 covers that.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Test (adding missing tests or correcting existing ones)

Status

  • Ready

Todo List

  • Implementation
  • Tests: two existing tests corrected. There is no new test for the startup race; I checked it by hand, as below.

How has this been tested ?

  • Default suite on this branch, fresh build: 140/140. I did not run the other suites locally.

  • The startup race, forced by adding sleep 3 to unbound's run script, before it starts unbound. Same image, only _parent/run differs:

    clamd restarts Result
    master's _parent/run 19, then s6 gave up same errors as in CI, clamd stays down
    this branch 0 no mail.err, clamd loads its database

    With unbound never starting, the warning is logged after 30 seconds and the other services start.

  • The two test fixes, forced in the default suite by making current-dbs.txt group-writable and logging the rspamd message to mail.err before the tests run. Without the fixes exactly those two tests fail (138/140), with them 140/140.

  • The mail.err test still fails when the file holds another error.

The race and test-fix checks ran before the last change to _parent/run, which only hides nc's output.

_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.
nc reports each successful connection on stderr, which ends up in the
container log twice per start.
"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 mailserver2#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant