Skip to content

Fix FPM timer event re-registration #4465

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

Closed
wants to merge 1 commit into from
Closed
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
26 changes: 15 additions & 11 deletions sapi/fpm/fpm/fpm_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,17 +433,16 @@ void fpm_event_loop(int err) /* {{{ */
/* trigger timers */
q = fpm_event_queue_timer;
while (q) {
struct fpm_event_queue_s *next = q->next;
fpm_clock_get(&now);
if (q->ev) {
if (timercmp(&now, &q->ev->timeout, >) || timercmp(&now, &q->ev->timeout, ==)) {
fpm_event_fire(q->ev);
/* sanity check */
if (fpm_globals.parent_pid != getpid()) {
return;
}
if (q->ev->flags & FPM_EV_PERSIST) {
fpm_event_set_timeout(q->ev, now);
} else { /* delete the event */
struct fpm_event_s *ev = q->ev;
if (ev->flags & FPM_EV_PERSIST) {
fpm_event_set_timeout(ev, now);
} else {
/* Delete the event. Make sure this happens before it is fired,
* so that the event callback may register the same timer again. */
q2 = q;
if (q->prev) {
q->prev->next = q->next;
Expand All @@ -457,13 +456,18 @@ void fpm_event_loop(int err) /* {{{ */
fpm_event_queue_timer->prev = NULL;
}
}
q = q->next;
free(q2);
continue;
}

fpm_event_fire(ev);

/* sanity check */
if (fpm_globals.parent_pid != getpid()) {
return;
}
}
}
q = q->next;
q = next;
}
}
}
Expand Down
56 changes: 56 additions & 0 deletions sapi/fpm/tests/reload-uses-sigkill-as-last-measure.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
--TEST--
If SIGQUIT and SIGTERM during reloading fail, SIGKILL should be sent
--SKIPIF--
<?php
include "skipif.inc";
if (!function_exists('pcntl_sigprocmask')) die('skip Requires pcntl_sigprocmask()');
?>
--FILE--
<?php

require_once "tester.inc";

$cfg = <<<EOT
[global]
error_log = {{FILE:LOG}}
pid = {{FILE:PID}}
process_control_timeout=1
[unconfined]
listen = {{ADDR}}
ping.path = /ping
ping.response = pong
pm = dynamic
pm.max_children = 5
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 1
EOT;

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

$tester = new FPM\Tester($cfg, $code);
$tester->start();
$tester->expectLogStartNotices();
$tester->request()->expectEmptyBody();
$tester->signal('USR2');
$tester->expectLogNotice('Reloading in progress ...');
$tester->expectLogNotice('reloading: .*');
$tester->expectLogNotice('using inherited socket fd=\d+, "127.0.0.1:\d+"');
$tester->expectLogStartNotices();
$tester->ping('{{ADDR}}');
$tester->terminate();
$tester->expectLogTerminatingNotices();
$tester->close();

?>
Done
--EXPECT--
Done
--CLEAN--
<?php
require_once "tester.inc";
FPM\Tester::clean();
?>
2 changes: 1 addition & 1 deletion sapi/fpm/tests/tester.inc
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ class Tester
$read = [$this->outDesc];
$write = null;
$except = null;
if (stream_select($read, $write, $except, 2 )) {
if (stream_select($read, $write, $except, 3)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does it need to be increased?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test case waits one second after sigquit to send sigterm and another second after that to send sigkill, so we need to wait for two seconds for the reload to occur. So the timeout should be larger than two seconds.

return fgets($this->outDesc);
} else {
return null;
Expand Down