Skip to content

Fix bug #77023: FPM cannot shutdown processes #8387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ PHP NEWS
- FPM:
. Fixed bug #76003 (FPM /status reports wrong number of active processe).
(Jakub Zelenka)
. Fixed bug #77023 (FPM cannot shutdown processes). (Jakub Zelenka)

- MySQLi:
. Fixed bug GH-8267 (MySQLi uses unsupported format specifier on Windows).
Expand Down
20 changes: 16 additions & 4 deletions sapi/fpm/fpm/fpm_process_ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ int fpm_pctl_kill(pid_t pid, int how) /* {{{ */
case FPM_PCTL_QUIT :
s = SIGQUIT;
break;
case FPM_PCTL_KILL:
s = SIGKILL;
break;
default :
break;
}
Expand Down Expand Up @@ -310,6 +313,17 @@ static void fpm_pctl_check_request_timeout(struct timeval *now) /* {{{ */
}
/* }}} */

static void fpm_pctl_kill_idle_child(struct fpm_child_s *child) /* {{{ */
{
if (child->idle_kill) {
fpm_pctl_kill(child->pid, FPM_PCTL_KILL);
} else {
child->idle_kill = 1;
fpm_pctl_kill(child->pid, FPM_PCTL_QUIT);
}
}
/* }}} */

static void fpm_pctl_perform_idle_server_maintenance(struct timeval *now) /* {{{ */
{
struct fpm_worker_pool_s *wp;
Expand Down Expand Up @@ -372,8 +386,7 @@ static void fpm_pctl_perform_idle_server_maintenance(struct timeval *now) /* {{{
fpm_request_last_activity(last_idle_child, &last);
fpm_clock_get(&now);
if (last.tv_sec < now.tv_sec - wp->config->pm_process_idle_timeout) {
last_idle_child->idle_kill = 1;
fpm_pctl_kill(last_idle_child->pid, FPM_PCTL_QUIT);
fpm_pctl_kill_idle_child(last_idle_child);
}

continue;
Expand All @@ -385,8 +398,7 @@ static void fpm_pctl_perform_idle_server_maintenance(struct timeval *now) /* {{{
zlog(ZLOG_DEBUG, "[pool %s] currently %d active children, %d spare children, %d running children. Spawning rate %d", wp->config->name, active, idle, wp->running_children, wp->idle_spawn_rate);

if (idle > wp->config->pm_max_spare_servers && last_idle_child) {
last_idle_child->idle_kill = 1;
fpm_pctl_kill(last_idle_child->pid, FPM_PCTL_QUIT);
fpm_pctl_kill_idle_child(last_idle_child);
wp->idle_spawn_rate = 1;
continue;
}
Expand Down
3 changes: 2 additions & 1 deletion sapi/fpm/fpm/fpm_process_ctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ enum {
FPM_PCTL_TERM,
FPM_PCTL_STOP,
FPM_PCTL_CONT,
FPM_PCTL_QUIT
FPM_PCTL_QUIT,
FPM_PCTL_KILL
};

#endif
65 changes: 65 additions & 0 deletions sapi/fpm/tests/bug77023-pm-dynamic-blocking-sigquit.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
--TEST--
FPM: Blocked SIGQUIT prevents idle process to be killed
--EXTENSIONS--
pcntl
--SKIPIF--
<?php
include "skipif.inc";
if (!function_exists('pcntl_sigprocmask')) die('skip Requires pcntl_sigprocmask()');
if (getenv('SKIP_SLOW_TESTS')) die('skip slow tests excluded by request');
?>
--FILE--
<?php

require_once "tester.inc";

$cfg = <<<EOT
[global]
error_log = {{FILE:LOG}}
pid = {{FILE:PID}}
[unconfined]
listen = {{ADDR}}
pm.status_path = /status
pm = dynamic
pm.max_children = 2
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 1
EOT;

$code = <<<EOT
<?php
pcntl_sigprocmask(SIG_BLOCK, [SIGQUIT, SIGTERM]);
usleep(300000);
EOT;


$tester = new FPM\Tester($cfg, $code);
$tester->start();
$tester->expectLogStartNotices();
$tester->multiRequest(2);
$tester->status([
'total processes' => 2,
]);
// wait for process to be killed
sleep(7);
$tester->expectLogWarning('child \\d+ exited on signal 9 \\(SIGKILL\\) after \\d+.\\d+ seconds from start', 'unconfined');
$tester->expectLogNotice('child \\d+ started', 'unconfined');
$tester->expectLogWarning('child \\d+ exited on signal 9 \\(SIGKILL\\) after \\d+.\\d+ seconds from start', 'unconfined');
$tester->expectLogNotice('child \\d+ started', 'unconfined');
$tester->status([
'total processes' => 1,
]);
$tester->terminate();
$tester->expectLogTerminatingNotices();
$tester->close();

?>
Done
--EXPECT--
Done
--CLEAN--
<?php
require_once "tester.inc";
FPM\Tester::clean();
?>