Skip to content

Commit e546d72

Browse files
turchanovnikic
authored andcommitted
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_timeout_track_finished 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 #4636)
1 parent 466f91b commit e546d72

File tree

8 files changed

+24
-4
lines changed

8 files changed

+24
-4
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ PHP NEWS
1010
. Fixed bug #78442 ('Illegal component' on exif_read_data since PHP7)
1111
(Kalle)
1212

13+
- FPM:
14+
. Fixed bug #78413 (request_terminate_timeout does not take effect after
15+
fastcgi_finish_request). (Sergei Turchanov)
16+
1317
- MBString:
1418
. Fixed bug #78579 (mb_decode_numericentity: args number inconsistency).
1519
(cmb)

UPGRADING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ FPM:
273273
disabling output decoration for workers output when catch_workers_output
274274
enabled.
275275
. The getallheaders() function is now also available.
276+
. In PHP 7.3.11 a new pool option
277+
request_terminate_timeout_track_finished has been added. When enabled,
278+
request_terminate_timeout will also apply after fastcgi_finish_request()
279+
has been called, as well as during execution of shutdown functions.
276280

277281
========================================
278282
4. Deprecated Functionality

sapi/fpm/fpm/fpm_conf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ static struct ini_value_parser_s ini_fpm_pool_options[] = {
147147
{ "request_slowlog_timeout", &fpm_conf_set_time, WPO(request_slowlog_timeout) },
148148
{ "request_slowlog_trace_depth", &fpm_conf_set_integer, WPO(request_slowlog_trace_depth) },
149149
{ "request_terminate_timeout", &fpm_conf_set_time, WPO(request_terminate_timeout) },
150+
{ "request_terminate_timeout_track_finished", &fpm_conf_set_boolean, WPO(request_terminate_timeout_track_finished) },
150151
{ "rlimit_files", &fpm_conf_set_integer, WPO(rlimit_files) },
151152
{ "rlimit_core", &fpm_conf_set_rlimit_core, WPO(rlimit_core) },
152153
{ "chroot", &fpm_conf_set_string, WPO(chroot) },
@@ -1674,6 +1675,7 @@ static void fpm_conf_dump() /* {{{ */
16741675
zlog(ZLOG_NOTICE, "\trequest_slowlog_timeout = %ds", wp->config->request_slowlog_timeout);
16751676
zlog(ZLOG_NOTICE, "\trequest_slowlog_trace_depth = %d", wp->config->request_slowlog_trace_depth);
16761677
zlog(ZLOG_NOTICE, "\trequest_terminate_timeout = %ds", wp->config->request_terminate_timeout);
1678+
zlog(ZLOG_NOTICE, "\trequest_terminate_timeout_track_finished = %s", BOOL2STR(wp->config->request_terminate_timeout_track_finished));
16771679
zlog(ZLOG_NOTICE, "\trlimit_files = %d", wp->config->rlimit_files);
16781680
zlog(ZLOG_NOTICE, "\trlimit_core = %d", wp->config->rlimit_core);
16791681
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
@@ -81,6 +81,7 @@ struct fpm_worker_pool_config_s {
8181
int request_slowlog_timeout;
8282
int request_slowlog_trace_depth;
8383
int request_terminate_timeout;
84+
int request_terminate_timeout_track_finished;
8485
int rlimit_files;
8586
int rlimit_core;
8687
char *chroot;

sapi/fpm/fpm/fpm_process_ctl.c

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

294294
for (wp = fpm_worker_all_pools; wp; wp = wp->next) {
295+
int track_finished = wp->config->request_terminate_timeout_track_finished;
295296
int terminate_timeout = wp->config->request_terminate_timeout;
296297
int slowlog_timeout = wp->config->request_slowlog_timeout;
297298
struct fpm_child_s *child;
298299

299300
if (terminate_timeout || slowlog_timeout) {
300301
for (child = wp->children; child; child = child->next) {
301-
fpm_request_check_timed_out(child, now, terminate_timeout, slowlog_timeout);
302+
fpm_request_check_timed_out(child, now, terminate_timeout, slowlog_timeout, track_finished);
302303
}
303304
}
304305
}

sapi/fpm/fpm/fpm_request.c

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

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

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

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

sapi/fpm/fpm/fpm_request.h

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

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

sapi/fpm/www.conf.in

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

342+
; The timeout set by 'request_terminate_timeout' ini option is not engaged after
343+
; application calls 'fastcgi_finish_request' or when application has finished and
344+
; shutdown functions are being called (registered via register_shutdown_function).
345+
; This option will enable timeout limit to be applied unconditionally
346+
; even in such cases.
347+
; Default Value: no
348+
;request_terminate_timeout_track_finished = no
349+
342350
; Set open file descriptor rlimit.
343351
; Default Value: system defined value
344352
;rlimit_files = 1024

0 commit comments

Comments
 (0)