php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74083 master PHP-fpm is stopped on multiple reloads
Submitted: 2017-02-11 06:03 UTC Modified: -
Votes:9
Avg. Score:4.4 ± 0.7
Reproduced:9 of 9 (100.0%)
Same Version:6 (66.7%)
Same OS:5 (55.6%)
From: afalaleev at plesk dot com Assigned:
Status: Open Package: FPM related
PHP Version: 7.1.1 OS: CentOS 7.x
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2017-02-11 06:03 UTC] 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.

Patches

php-74083_draft-block-signal-reload_2018-07-10.patch (last revision 2018-07-10 10:38 UTC) by mnikulin at plesk dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-07-10 10:44 UTC] 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
 [2018-07-11 08:28 UTC] 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.
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Mon Oct 15 16:01:26 2018 UTC