Bug #74083 [Com]: master PHP-fpm is stopped on multiple reloads

From: Date: Tue, 16 Oct 2018 04:53:08 +0000
Subject: Bug #74083 [Com]: master PHP-fpm is stopped on multiple reloads
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217586@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74083&edit=1

 ID:                 74083
 Comment by:         mnikulin at plesk dot com
 Reported by:        afalaleev at plesk dot com
 Summary:            master PHP-fpm is stopped on multiple reloads
 Status:             Open
 Type:               Bug
 Package:            FPM related
 Operating System:   CentOS 7.x
 PHP Version:        7.1.1
 Block user comment: N
 Private report:     N

 New Comment:

I have refreshed the patch. I recommend to apply patches for #76601
on the top of it. It is made for 7.2.11 but can be applied to
7.1.23, 7.0.32, and 5.6.38 as well.


Previous Comments:
------------------------------------------------------------------------
[2018-07-11 08:28:40] mnikulin at plesk dot com

It seems that combining the attached patch with the one from https://bugs.php.net/bug.php?id=76601 helps in the
case of concurrent reload SIGUSR2 signals. At least it may be considered as quick plumbing.

------------------------------------------------------------------------
[2018-07-10 10:44:37] mnikulin at plesk dot com

Let's start discussion in which way this bug can be fixed with a patch that uses sigprocmask()
to block other reload signals during execvp() and early initialization.

Do not use it in production. Instead of simply dead processes you may get more peculiar state
described in https://bugs.php.net/bug.php?id=76601

------------------------------------------------------------------------
[2017-02-11 06:03:23] afalaleev at plesk dot com

Description:
------------
PHP-FPM is stopped, when it receive more than one SIGUSR2 in a short time.
 
The reason:
- On receiving SIGUSR2 php-fpm calls execvp(path, ...)
- Process starts. 
--  It inherit all opened handles.
--  But all signal handlers is reseted to SIG_DFL

So, if SIGUSR2 income before process change the signal handler, it will exit, because it's a
default action on receiving SIGUSR2.

The bug is actual for all versions of PHP: 5.6, 7.0, 7.1.

The possible decision (in attached patch) is to block the signal before execvp(...), and unblock it
after changing the signal handlers.

The attached patch solve the problem for all versions of PHP: 5.6, 7.0, 7.1.


Test script:
---------------
With a high probability, it may happened on send 2 reloads without any timeout:

# systemctl reload php71-fpm.service; systemctl reload php71-fpm.service

For greater reliability, the following script can be executed:

# for i in $(seq 1 100); do systemctl reload php71-fpm.service; done
 

Expected result:
----------------
# systemctl status php71-fpm.service 
● php71-fpm.service - The PHP 7.1.1 FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php71-fpm.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2017-02-11 12:41:10 +07; 6min ago
  Process: 17828 ExecReload=/bin/kill -USR2 $MAINPID (code=exited, status=0/SUCCESS)
 Main PID: 17002 (php-fpm)
   Status: "Processes active: 0, idle: 0, Requests: 0, slow: 0, Traffic: 0req/sec"
   CGroup: /system.slice/php71-fpm.service
           └─17002 php-fpm: master process (/opt/php/7.1/etc/php-fpm.conf)

Feb 11 12:41:30 a10-52-35-250.qa.ru systemd[1]: Reloaded The PHP 7.1.1 FastCGI Process Manager.
Feb 11 12:41:30 a10-52-35-250.qa.ru systemd[1]: Reloaded The PHP 7.1.1 FastCGI Process Manager.
Feb 11 12:41:30 a10-52-35-250.qa.ru systemd[1]: Reloaded The PHP 7.1.1 FastCGI Process Manager.
Feb 11 12:41:30 a10-52-35-250.qa.ru systemd[1]: Reloaded The PHP 7.1.1 FastCGI Process Manager.
Feb 11 12:41:30 a10-52-35-250.qa.ru systemd[1]: Reloaded The PHP 7.1.1 FastCGI Process Manager.
Feb 11 12:41:30 a10-52-35-250.qa.ru systemd[1]: Reloaded The PHP 7.1.1 FastCGI Process Manager.
Feb 11 12:41:30 a10-52-35-250.qa.ru systemd[1]: Reloaded The PHP 7.1.1 FastCGI Process Manager.


Actual result:
--------------
# systemctl status php71-fpm.service; 
● php71-fpm.service - The PHP 7.1.1 FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php71-fpm.service; enabled; vendor preset: disabled)
   Active: failed (Result: signal) since Sat 2017-02-11 12:27:11 +07; 13min ago
  Process: 16348 ExecReload=/bin/kill -USR2 $MAINPID (code=exited, status=0/SUCCESS)
 Main PID: 15808 (code=killed, signal=USR2)
   Status: "Processes active: 0, idle: 0, Requests: 0, slow: 0, Traffic: 0req/sec"

Feb 11 12:27:12 a10-52-35-250.qa.ru systemd[1]: Unit php71-fpm.service cannot be reloaded because it
is inactive.
Feb 11 12:27:12 a10-52-35-250.qa.ru systemd[1]: Unit php71-fpm.service cannot be reloaded because it
is inactive.
Feb 11 12:27:12 a10-52-35-250.qa.ru systemd[1]: Unit php71-fpm.service cannot be reloaded because it
is inactive.
Feb 11 12:27:12 a10-52-35-250.qa.ru systemd[1]: Unit php71-fpm.service cannot be reloaded because it
is inactive.
Feb 11 12:27:12 a10-52-35-250.qa.ru systemd[1]: Unit php71-fpm.service cannot be reloaded because it
is inactive.
Feb 11 12:27:12 a10-52-35-250.qa.ru systemd[1]: Unit php71-fpm.service cannot be reloaded because it
is inactive.
Feb 11 12:27:12 a10-52-35-250.qa.ru systemd[1]: Unit php71-fpm.service cannot be reloaded because it
is inactive.


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=74083&edit=1


Thread (6 messages)

« previous php.bugs (#217586) next »