Skip to content

Commit 57e6699

Browse files
committed
Fix #78413: php-fpm request_terminate_timeout does not take effect after fastcgi_finish_request
To retain legacy behavior I decided to add an option to control request termination logic. If request_terminate_strict is set then request will be tracked for time limits even after fastcgi_finish_request was called. This patch depends on the fix provided in BUG 78469 (otherwise php-fpm workers listening on named pipes on Windows will be erroneously terminated) (PR php#4636)
1 parent 88ab374 commit 57e6699

File tree

6 files changed

+14
-4
lines changed

6 files changed

+14
-4
lines changed

sapi/fpm/fpm/fpm_conf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ static struct ini_value_parser_s ini_fpm_pool_options[] = {
148148
{ "request_slowlog_timeout", &fpm_conf_set_time, WPO(request_slowlog_timeout) },
149149
{ "request_slowlog_trace_depth", &fpm_conf_set_integer, WPO(request_slowlog_trace_depth) },
150150
{ "request_terminate_timeout", &fpm_conf_set_time, WPO(request_terminate_timeout) },
151+
{ "request_terminate_strict", &fpm_conf_set_boolean, WPO(request_terminate_strict) },
151152
{ "rlimit_files", &fpm_conf_set_integer, WPO(rlimit_files) },
152153
{ "rlimit_core", &fpm_conf_set_rlimit_core, WPO(rlimit_core) },
153154
{ "chroot", &fpm_conf_set_string, WPO(chroot) },
@@ -1664,6 +1665,7 @@ static void fpm_conf_dump() /* {{{ */
16641665
zlog(ZLOG_NOTICE, "\trequest_slowlog_timeout = %ds", wp->config->request_slowlog_timeout);
16651666
zlog(ZLOG_NOTICE, "\trequest_slowlog_trace_depth = %d", wp->config->request_slowlog_trace_depth);
16661667
zlog(ZLOG_NOTICE, "\trequest_terminate_timeout = %ds", wp->config->request_terminate_timeout);
1668+
zlog(ZLOG_NOTICE, "\trequest_terminate_strict = %s", BOOL2STR(wp->config->request_terminate_strict));
16671669
zlog(ZLOG_NOTICE, "\trlimit_files = %d", wp->config->rlimit_files);
16681670
zlog(ZLOG_NOTICE, "\trlimit_core = %d", wp->config->rlimit_core);
16691671
zlog(ZLOG_NOTICE, "\tchroot = %s", STR2STR(wp->config->chroot));

sapi/fpm/fpm/fpm_conf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct fpm_worker_pool_config_s {
8080
int request_slowlog_timeout;
8181
int request_slowlog_trace_depth;
8282
int request_terminate_timeout;
83+
int request_terminate_strict;
8384
int rlimit_files;
8485
int rlimit_core;
8586
char *chroot;

sapi/fpm/fpm/fpm_process_ctl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,14 @@ static void fpm_pctl_check_request_timeout(struct timeval *now) /* {{{ */
293293
struct fpm_worker_pool_s *wp;
294294

295295
for (wp = fpm_worker_all_pools; wp; wp = wp->next) {
296+
int strict = wp->config->request_terminate_strict;
296297
int terminate_timeout = wp->config->request_terminate_timeout;
297298
int slowlog_timeout = wp->config->request_slowlog_timeout;
298299
struct fpm_child_s *child;
299300

300301
if (terminate_timeout || slowlog_timeout) {
301302
for (child = wp->children; child; child = child->next) {
302-
fpm_request_check_timed_out(child, now, terminate_timeout, slowlog_timeout);
303+
fpm_request_check_timed_out(child, now, terminate_timeout, slowlog_timeout, strict);
303304
}
304305
}
305306
}

sapi/fpm/fpm/fpm_request.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ void fpm_request_finished() /* {{{ */
222222
}
223223
/* }}} */
224224

225-
void fpm_request_check_timed_out(struct fpm_child_s *child, struct timeval *now, int terminate_timeout, int slowlog_timeout) /* {{{ */
225+
void fpm_request_check_timed_out(struct fpm_child_s *child, struct timeval *now, int terminate_timeout, int slowlog_timeout, int strict) /* {{{ */
226226
{
227227
struct fpm_scoreboard_proc_s proc, *proc_p;
228228

@@ -244,7 +244,7 @@ void fpm_request_check_timed_out(struct fpm_child_s *child, struct timeval *now,
244244
}
245245
#endif
246246

247-
if (proc.request_stage > FPM_REQUEST_ACCEPTING && proc.request_stage < FPM_REQUEST_END) {
247+
if (proc.request_stage > FPM_REQUEST_ACCEPTING && ((proc.request_stage < FPM_REQUEST_END) || strict)) {
248248
char purified_script_filename[sizeof(proc.script_filename)];
249249
struct timeval tv;
250250

sapi/fpm/fpm/fpm_request.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ void fpm_request_finished(); /* request processed: cleaning current request *
1414
struct fpm_child_s;
1515
struct timeval;
1616

17-
void fpm_request_check_timed_out(struct fpm_child_s *child, struct timeval *tv, int terminate_timeout, int slowlog_timeout);
17+
void fpm_request_check_timed_out(struct fpm_child_s *child, struct timeval *tv, int terminate_timeout, int slowlog_timeout, int strict);
1818
int fpm_request_is_idle(struct fpm_child_s *child);
1919
const char *fpm_request_get_stage_name(int stage);
2020
int fpm_request_last_activity(struct fpm_child_s *child, struct timeval *tv);

sapi/fpm/www.conf.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,12 @@ pm.max_spare_servers = 3
339339
; Default Value: 0
340340
;request_terminate_timeout = 0
341341

342+
; When application calls fastcgi_finish_request it will inhibit request
343+
; termination after request_terminate_timeout time limit. This option will enable
344+
; timeout limit to be applied unconditionally even after fastcgi_finish_request.
345+
; To retain legacy behavior the default is 'no'
346+
;request_terminate_strict = no
347+
342348
; Set open file descriptor rlimit.
343349
; Default Value: system defined value
344350
;rlimit_files = 1024

0 commit comments

Comments
 (0)