Skip to content

Commit 42fff9c

Browse files
Fix #78405: FPM with keepalive kills workers after $terminate_timeout
after enabling keepalives in nginx, fpm (configured with relative short request_terminate_timeout) starts killing workers after they haven't handled a request for that period. This is wrong, these workers are idle and awaiting new requests. Fix this by detecting keepalive requests, and threating workers as idle. Also don't run terminate or slowlog checks for idle workers
1 parent bc1d780 commit 42fff9c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

sapi/fpm/fpm/fpm_request.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ void fpm_request_reading_headers(void)
8181
return;
8282
}
8383

84+
// with keepalive enabled on the webserver, a request skips the ACCEPTING stage
85+
if (proc->request_stage == FPM_REQUEST_FINISHED)
86+
proc->handling_keepalive = 1;
87+
8488
proc->request_stage = FPM_REQUEST_READING_HEADERS;
8589
proc->tv = now;
8690
proc->accepted = now;
@@ -241,7 +245,9 @@ void fpm_request_check_timed_out(struct fpm_child_s *child, struct timeval *now,
241245
}
242246
#endif
243247

244-
if (proc.request_stage > FPM_REQUEST_ACCEPTING && ((proc.request_stage < FPM_REQUEST_END) || track_finished)) {
248+
if (!fpm_request_is_idle(child) &&
249+
proc.request_stage > FPM_REQUEST_ACCEPTING &&
250+
((proc.request_stage < FPM_REQUEST_END) || track_finished)) {
245251
char purified_script_filename[sizeof(proc.script_filename)];
246252
struct timeval tv;
247253

@@ -288,7 +294,7 @@ int fpm_request_is_idle(struct fpm_child_s *child) /* {{{ */
288294
return 0;
289295
}
290296

291-
return proc->request_stage == FPM_REQUEST_ACCEPTING;
297+
return proc->request_stage == FPM_REQUEST_ACCEPTING || (proc->handling_keepalive && proc->request_stage == FPM_REQUEST_READING_HEADERS);
292298
}
293299
/* }}} */
294300

sapi/fpm/fpm/fpm_scoreboard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct fpm_scoreboard_proc_s {
2828
pid_t pid;
2929
unsigned long requests;
3030
enum fpm_request_stage_e request_stage;
31+
int handling_keepalive;
3132
struct timeval accepted;
3233
struct timeval duration;
3334
time_t accepted_epoch;

0 commit comments

Comments
 (0)