Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 16 Mar 2019 01:12:31 +0000
From:      bugzilla-noreply@freebsd.org
To:        bugs@FreeBSD.org
Subject:   [Bug 236564] Anticongestion function does not work as is expected.
Message-ID:  <bug-236564-227@https.bugs.freebsd.org/bugzilla/>

next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D236564

            Bug ID: 236564
           Summary: Anticongestion function does not work as is expected.
           Product: Base System
           Version: CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: yasu@utahime.org
             Flags: mfc-stable11?, mfc-stable12?

Created attachment 202893
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D202893&action=
=3Dedit
Patch file

I. Summary

Under some conditions anticongestion function in /etc/default/periodic.conf
does not work as is expected

II. Backgroup

Anticongestion function is defined in /etc/default/periodic.conf. If I
understand correctly the purpose of it is to insert random sleep just one t=
ime
through all periodic scripts even if it is called more than once.

III. Problem Description

Currently (at base r345186) /etc/periodic/daily/480.leapfile-ntpd is a only
periodic script on base system that calls anticongestion function. So let me
assume following situation.

* There is no /etc/weekly.local.
* There is no periodic script under /usr/local/etc/periodic/security.
* There is only one periodic script 123-foo under
/usr/local/etc/periodic/weekly.
* 123-foo calls anticongestion function in it.

Then what happens when 'periodic weekly' is executed from cron? Periodic(8)
executes scripts with following order.

1. /etc/periodic/weekly/310.locate
2. /etc/periodic/weekly/320.whatis
3. /etc/periodic/weekly/340.noid
4. /etc/periodic/weekly/450.status-security
  4.01. /etc/periodic/security/100.chksetuid
  4.02. /etc/periodic/security/110.neggrpperm
  4.03. /etc/periodic/security/200.chkmounts
  4.04. /etc/periodic/security/300.chkuid0
  4.05. /etc/periodic/security/400.passwdless
  4.06. /etc/periodic/security/410.logincheck
  4.07. /etc/periodic/security/500.ipfwdenied
  4.08. /etc/periodic/security/510.ipfdenied
  4.09. /etc/periodic/security/520.pfdenied
  4.10. /etc/periodic/security/550.ipfwlimit
  4.11. /etc/periodic/security/610.ipf6denied
  4.12. /etc/periodic/security/700.kernelmsg
  4.13. /etc/periodic/security/800.loginfail
  4.14. /etc/periodic/security/900.tcpwrap
5. /etc/periodic/weekly/999.local
6. /usr/local/etc/periodic/weekly/123-foo

As is explained above no script under /etc/periodic/weekly and
/etc/periodic/security calls anticongestion function. So expected behavior =
is
that anticongestion function is called and random sleep insterted at step 6.
But it is different from real one. What really happens is that anticongesti=
on
function is called at step 6 but random sleep is not inserted.

IV. Source of Problem

The source of problem is that periodic(8) is executed twice when 'periodic
weekly' is executed from cron. That is, first when it is executed from cron,
and next when /etc/periodic/weekly/450.status-security is executed.

There is following codes at line 79-81 of /usr/sbin/periodic.

----------------------------------------------------------------------
if [ -z "$PERIODIC_ANTICONGESTION_FILE" ] ; then
        export PERIODIC_ANTICONGESTION_FILE=3D`mktemp
${TMPDIR:-/tmp}/periodic.anticongestion.XXXXXXXXXX`
fi
----------------------------------------------------------------------

And there is following code at last line of /usr/sbin/periodic.

----------------------------------------------------------------------
rm -f $PERIODIC_ANTICONGESTION_FILE
----------------------------------------------------------------------

Anticongestion function is defined in /etc/default/periodic.conf as followi=
ng.

----------------------------------------------------------------------
        # Sleep for a random amount of time in order to mitigate the thunde=
ring
        # herd problem of multiple hosts running periodic simultaneously.
        # Will not sleep when used interactively.
        # Will sleep at most once per invocation of periodic
        anticongestion() {
                [ -n "$PERIODIC_IS_INTERACTIVE" ] && return
                if [ -f "$PERIODIC_ANTICONGESTION_FILE" ]; then
                        rm -f $PERIODIC_ANTICONGESTION_FILE
                        sleep `jot -r 1 0 ${anticongestion_sleeptime}`
                fi
        }
----------------------------------------------------------------------

So what really happens is as following.

a. 'periodic weekly' is executed from cron and master process of periodic(8=
) is
created.=20
b. Because PERIODIC_ANTICONGESTION_FILE is not set in master process, tempo=
rary
file is created, its path is set as value of PERIODIC_ANTICONGESTION_FILE a=
nd
PERIODIC_ANTICONGESTION_FILE is exported.
c. /etc/periodic/weekly/450.status-security is executed and slave process of
periodic(8) is created
d. Because PERIODIC_ANTICONGESTION_FILE is already set in slave process,
another temporary file is not created and the value of
PERIODIC_ANTICONGESTION_FILE is not changed.
e. At the end of slave process temporary file created at step b is removed.
f. Slave process exits and return to master process.
g. /usr/local/etc/periodic/weekly/123-foo is executed and anticongestion
function is called.
h. Because temporary file created at step b is already removed at step e,
random sleep is not inserted.

In this way anticongestion function does not work as is expected.

V. Solution

By applying attached patch the problem is fixed.

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-236564-227>