Skip to content

Commit 192f374

Browse files
committed
Fix fpm timer event re-registration
1 parent b59a938 commit 192f374

File tree

3 files changed

+70
-10
lines changed

3 files changed

+70
-10
lines changed

sapi/fpm/fpm/fpm_events.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -436,14 +436,12 @@ void fpm_event_loop(int err) /* {{{ */
436436
fpm_clock_get(&now);
437437
if (q->ev) {
438438
if (timercmp(&now, &q->ev->timeout, >) || timercmp(&now, &q->ev->timeout, ==)) {
439-
fpm_event_fire(q->ev);
440-
/* sanity check */
441-
if (fpm_globals.parent_pid != getpid()) {
442-
return;
443-
}
444-
if (q->ev->flags & FPM_EV_PERSIST) {
445-
fpm_event_set_timeout(q->ev, now);
446-
} else { /* delete the event */
439+
struct fpm_event_s *ev = q->ev;
440+
if (ev->flags & FPM_EV_PERSIST) {
441+
fpm_event_set_timeout(ev, now);
442+
} else {
443+
/* Delete the event. Make sure this happens before it is fired,
444+
* so that the event callback may register the same timer again. */
447445
q2 = q;
448446
if (q->prev) {
449447
q->prev->next = q->next;
@@ -459,7 +457,13 @@ void fpm_event_loop(int err) /* {{{ */
459457
}
460458
q = q->next;
461459
free(q2);
462-
continue;
460+
}
461+
462+
fpm_event_fire(ev);
463+
464+
/* sanity check */
465+
if (fpm_globals.parent_pid != getpid()) {
466+
return;
463467
}
464468
}
465469
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
--TEST--
2+
If SIGQUIT and SIGTERM during reloading fail, SIGKILL should be sent
3+
--SKIPIF--
4+
<?php
5+
include "skipif.inc";
6+
if (!function_exists('pcntl_sigprocmask')) die('skip Requires pcntl_sigprocmask()');
7+
?>
8+
--FILE--
9+
<?php
10+
11+
require_once "tester.inc";
12+
13+
$cfg = <<<EOT
14+
[global]
15+
error_log = {{FILE:LOG}}
16+
pid = {{FILE:PID}}
17+
process_control_timeout=1
18+
[unconfined]
19+
listen = {{ADDR}}
20+
ping.path = /ping
21+
ping.response = pong
22+
pm = dynamic
23+
pm.max_children = 5
24+
pm.start_servers = 1
25+
pm.min_spare_servers = 1
26+
pm.max_spare_servers = 1
27+
EOT;
28+
29+
$code = <<<EOT
30+
<?php
31+
pcntl_sigprocmask(SIG_BLOCK, [SIGQUIT, SIGTERM]);
32+
EOT;
33+
34+
$tester = new FPM\Tester($cfg, $code);
35+
$tester->start();
36+
$tester->expectLogStartNotices();
37+
$tester->request()->expectEmptyBody();
38+
$tester->signal('USR2');
39+
$tester->expectLogNotice('Reloading in progress ...');
40+
$tester->expectLogNotice('reloading: .*');
41+
$tester->expectLogNotice('using inherited socket fd=\d+, "127.0.0.1:\d+"');
42+
$tester->expectLogStartNotices();
43+
$tester->ping('{{ADDR}}');
44+
$tester->terminate();
45+
$tester->expectLogTerminatingNotices();
46+
$tester->close();
47+
48+
?>
49+
Done
50+
--EXPECT--
51+
Done
52+
--CLEAN--
53+
<?php
54+
require_once "tester.inc";
55+
FPM\Tester::clean();
56+
?>

sapi/fpm/tests/tester.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ class Tester
627627
$read = [$this->outDesc];
628628
$write = null;
629629
$except = null;
630-
if (stream_select($read, $write, $except, 2 )) {
630+
if (stream_select($read, $write, $except, 3)) {
631631
return fgets($this->outDesc);
632632
} else {
633633
return null;

0 commit comments

Comments
 (0)