PHP fastcgi with PHP_FCGI_CHILDREN doesn't kill children when parent is killed

Bug #162082 reported by Jakob Unterwurzacher
16
This bug affects 1 person
Affects Status Importance Assigned to Milestone
php
Unknown
Unknown
Debian
Fix Released
Unknown
php5 (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

This Bug is already reported here: http://bugs.php.net/bug.php?id=40286
and here: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=431799 (inactive)

I see it in Ubuntu Hardy now:
PHP 5.2.4-2ubuntu5 with Suhosin-Patch 0.9.6.2 (cgi-fcgi)

Quoting from: http://bugs.php.net/bug.php?id=40286 :
When running PHP in FastCGI mode with a fastCGI apache module (such a
mod_fcgid), all is running fine when PHP_FCGI_CHILDREN unset : only 1
process spawned. When using PHP_FCGI_CHILDREN=n, the PHP parent process
forks n childs, and the parent acts as a manager between the child
processes, wait()ing to respawn them if they are killed or exit. The
problem happens when the FastCGI process manager handled by the apache
module has to kill the parent PHP process (it only knows the parent's
PID) for any reason such as idle timeout, max lifetime, etc.

Problem:
While the PHP parent process is properly killed by the FastCGI process
manager, the children aren't killed, but instead stay alive, waiting for
a new request which will never come.
This sooner or later uses up all availible RAM and lead to a DOS.

Workaround: See comments.

Revision history for this message
Jakob Unterwurzacher (jakobunt) wrote :

Workaround: Kill those lurking process regularily using a cronjob.
This works for me, it should be reasonably safe to use (who has php started by init?).

#!/bin/bash
pkill -f -x /usr/lib/cgi-bin/php -P 1

Revision history for this message
Nikolas Moraitis (nikolazx) wrote : how do i remove myself from this list?

2007/11/12, Jakob Unterwurzacher <email address hidden>:
>
> Workaround: Kill those lurking process regularily using a cronjob.
> This works for me, it should be reasonably safe to use (who has php
> started by init?).
>
> #!/bin/bash
> pkill -f -x /usr/lib/cgi-bin/php -P 1
>
> --
> PHP fastcgi with PHP_FCGI_CHILDREN doesn't kill children when parent is
> killed
> https://bugs.launchpad.net/bugs/162082
> You received this bug notification because you are a member of Ubuntu
> Server Team, which is a bug contact for php5 in ubuntu.
>

Revision history for this message
Jakob Unterwurzacher (jakobunt) wrote :
Revision history for this message
Jakob Unterwurzacher (jakobunt) wrote :

(That was to be added to the "Comment on most recent change" for Affects/php, but it didn't quite work as expected)

Revision history for this message
Chuck Short (zulcss) wrote :

If possible could you test this with hardy?

Thanks
chuck

Changed in php5:
status: New → Incomplete
Revision history for this message
Jakob Unterwurzacher (jakobunt) wrote :

Still exists in Hardy.

Attached is a pstree (phpkiller.sh output - see next post) showing lots of orphaned php processes (some usernames #'d).

Revision history for this message
Jakob Unterwurzacher (jakobunt) wrote :

Last version of the kill-all-orphaned-phps workaround attached.

I recommend to run it hourly to catch php parents that die suddenly
AND (more important)
to add it in your /etc/logrotate.d/apache2 in postrotate after apache restart, because this creates lots of orphaned processes most of the time.

Changed in php5:
status: Incomplete → Confirmed
description: updated
Revision history for this message
Yann Hamon (yannh) wrote :

I have the same issue but without PHP_FCGI_CHILDREN set.

yann@jok:/proc/15237$ ps -ef | fgrep 15237
ufr_doc 15237 1 0 04:20 ? 00:00:00 /usr/lib/cgi-bin/php5 -d magic_quotes_gpc=off
yann 26564 24593 0 14:15 pts/0 00:00:00 fgrep 15237

yann@jok:/proc/15237$ sudo cat environ
PATH=/usr/local/bin:/usr/bin:/binPWD=/nfs/www/fr/doc/binSHLVL=0PHP_FCGI_MAX_REQUESTS=1000

Revision history for this message
Yann Hamon (yannh) wrote :

Ah, and it seems to affect python processes, too.

Revision history for this message
Daniel Hahler (blueyed) wrote :

JFI: you may want to use php-fpm instead. E.g. via the packages provided at dotdeb.org.

Daniel Hahler (blueyed)
Changed in php:
importance: Undecided → Unknown
status: New → Unknown
Changed in debian:
status: Confirmed → Fix Released
Revision history for this message
Clint Byrum (clint-fewbar) wrote :

Fixed in Debian a long time ago.

Changed in php5 (Ubuntu):
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.