From 6b7a76af9aed0d98e7903fb29a1367f6000c0df9 Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Sun, 20 Jul 2025 18:32:49 +0200 Subject: [PATCH] Fix GH-18956: PHP-FPM Process Count Inconsistencies This fixes incorrect decrement of the active number of processes. This was done in accepting stage before incrementing which is problematic if there are already some running processes as it decrements their number first and result in incorrect total (lower than the actual number). In addition it also fixes GH-14212 as accept is done just once for keepalive connection so in this case the number of active connection just increasing with each request. Closes GH-19191 --- sapi/fpm/fpm/fpm_main.c | 2 ++ sapi/fpm/fpm/fpm_request.c | 10 ++++++++-- sapi/fpm/fpm/fpm_request.h | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c index 2a649b9a13501..9e506f7089c4d 100644 --- a/sapi/fpm/fpm/fpm_main.c +++ b/sapi/fpm/fpm/fpm_main.c @@ -1973,6 +1973,8 @@ consult the installation file that came with this distribution, or visit \n\ fpm_stdio_flush_child(); + fpm_request_shutdown(); + requests++; if (UNEXPECTED(max_requests && (requests == max_requests))) { fcgi_request_set_keep(request, 0); diff --git a/sapi/fpm/fpm/fpm_request.c b/sapi/fpm/fpm/fpm_request.c index 9ea7d8aeaaa35..ae8711981713d 100644 --- a/sapi/fpm/fpm/fpm_request.c +++ b/sapi/fpm/fpm/fpm_request.c @@ -54,8 +54,8 @@ void fpm_request_accepting(void) proc->tv = now; fpm_scoreboard_proc_release(proc); - /* idle++, active-- */ - fpm_scoreboard_update_commit(1, -1, 0, 0, 0, 0, 0, FPM_SCOREBOARD_ACTION_INC, NULL); + /* idle++ */ + fpm_scoreboard_update_commit(1, 0, 0, 0, 0, 0, 0, FPM_SCOREBOARD_ACTION_INC, NULL); } void fpm_request_reading_headers(void) @@ -220,6 +220,12 @@ void fpm_request_finished(void) fpm_scoreboard_proc_release(proc); } +void fpm_request_shutdown(void) +{ + /* active-- */ + fpm_scoreboard_update(0, -1, 0, 0, 0, 0, 0, FPM_SCOREBOARD_ACTION_INC, NULL); +} + void fpm_request_check_timed_out(struct fpm_child_s *child, struct timeval *now, int terminate_timeout, int slowlog_timeout, int track_finished) /* {{{ */ { struct fpm_scoreboard_proc_s proc, *proc_p; diff --git a/sapi/fpm/fpm/fpm_request.h b/sapi/fpm/fpm/fpm_request.h index 1dcc7f78902fc..aa6e6e5e422cc 100644 --- a/sapi/fpm/fpm/fpm_request.h +++ b/sapi/fpm/fpm/fpm_request.h @@ -15,6 +15,8 @@ void fpm_request_executing(void); void fpm_request_end(void); /* request processed: cleaning current request */ void fpm_request_finished(void); +/* request post shutdown: decrement active */ +void fpm_request_shutdown(void); struct fpm_child_s; struct timeval;