[Bug 955681] [NEW] php5-common's /etc/cron.d/php5 session expiration can go crazy
AJ
955681 at bugs.launchpad.net
Thu Mar 15 03:45:34 UTC 2012
Public bug reported:
In this cron command:
$ cat /etc/issue.net
Ubuntu 11.10
$ cat /etc/cron.d/php5
# /etc/cron.d/php5: crontab fragment for php5
# This purges session files older than X, where X is defined in seconds
# as the largest value of session.gc_maxlifetime from all your php.ini
# files, or 24 minutes if not defined. See /usr/lib/php5/maxlifetime
# Look for and purge old sessions every 30 minutes
09,39 * * * * root [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) ! -execdir fuser -s {} 2>/dev/null \; -delete
There appears to be a problem with fuser where it can leave subprocesses
around that eventually go zombie after the parent fuser exits. On
heavily loaded systems this can cause a race condition where subsequent
fuser calls after the first need to check an exponentially increasing
number of processes until the system runs out of memory or PIDs.
We worked around the problem by modifying the script thus:
[ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) | while read file ; do if ! fuser -s $file ; then rm $file ; sleep 2 ; fi ; done
Which does the same thing but waits 2secs between each fuser call to prevent the problem from occurring. Of course this significantly slows down processing time and is not a perfect fix anyway on an even heavier loaded system.
Our final modification is just to delete all files older than the max lifetime regardless of whether they are being used or not:
[ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) -delete
For our application this works fine.
I believe to fix this problem either fuser needs to be changed so it
doesn't leave children around after exiting, or another tool should be
used instead (lsof?). It may also be possible to fix this with a call to
the sh builtin 'wait' after each fuser to clean up the children/zombies
(would require the exec loop to be pulled out of the find command, as
per our first modification), but we didn't test this and can't easily
repro the scenario.
** Affects: php5 (Ubuntu)
Importance: Undecided
Status: New
--
You received this bug notification because you are a member of Ubuntu
Server Team, which is subscribed to php5 in Ubuntu.
https://bugs.launchpad.net/bugs/955681
Title:
php5-common's /etc/cron.d/php5 session expiration can go crazy
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/php5/+bug/955681/+subscriptions
More information about the Ubuntu-server-bugs
mailing list