From b68ef838082b9d25564b02f116461754eace8225 Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Wed, 27 Nov 2024 22:56:55 +0100 Subject: [PATCH] Fix GH-16932: wrong FPM status output --- sapi/fpm/fpm/fpm_request.c | 2 +- sapi/fpm/tests/gh16932-scoreboard-reset.phpt | 56 ++++++++++++++++++++ sapi/fpm/tests/response.inc | 25 ++++++++- 3 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 sapi/fpm/tests/gh16932-scoreboard-reset.phpt diff --git a/sapi/fpm/fpm/fpm_request.c b/sapi/fpm/fpm/fpm_request.c index 92c6fa8f2cca9..f07c6979f7064 100644 --- a/sapi/fpm/fpm/fpm_request.c +++ b/sapi/fpm/fpm/fpm_request.c @@ -201,7 +201,7 @@ void fpm_request_end(void) fpm_scoreboard_proc_release(proc); /* memory_peak */ - fpm_scoreboard_update_commit(0, 0, 0, 0, 0, 0, 0, proc->memory, FPM_SCOREBOARD_ACTION_SET, NULL); + fpm_scoreboard_update_commit(-1, -1, -1, -1, -1, -1, -1, proc->memory, FPM_SCOREBOARD_ACTION_SET, NULL); } void fpm_request_finished(void) diff --git a/sapi/fpm/tests/gh16932-scoreboard-reset.phpt b/sapi/fpm/tests/gh16932-scoreboard-reset.phpt new file mode 100644 index 0000000000000..18092a53f7aff --- /dev/null +++ b/sapi/fpm/tests/gh16932-scoreboard-reset.phpt @@ -0,0 +1,56 @@ +--TEST-- +FPM: GH-16932 - scoreboard fields are reset after the request +--EXTENSIONS-- +pcntl +--SKIPIF-- + +--FILE-- +start(extensions: ['pcntl']); +$tester->expectLogStartNotices(); +$tester->request(); +$tester->request(); +$tester->request(); +$tester->request(); +$tester + ->request(uri: '/status', query: 'json') + ->expectJsonBodyPatternForStatusField('accepted conn', '5'); +$tester->terminate(); +$tester->expectLogTerminatingNotices(); +$tester->close(); + +?> +Done +--EXPECT-- +Done +--CLEAN-- + diff --git a/sapi/fpm/tests/response.inc b/sapi/fpm/tests/response.inc index b784df3164f46..aefd2e027c67d 100644 --- a/sapi/fpm/tests/response.inc +++ b/sapi/fpm/tests/response.inc @@ -148,6 +148,29 @@ class Response extends BaseResponse return $this; } + /** + * Expect status field with value that matches the supplied pattern. + * + * @param string $fieldName + * @param string $pattern + * + * @return Response + */ + public function expectJsonBodyPatternForStatusField(string $fieldName, string $pattern): Response + { + $rawData = $this->getBody('application/json'); + $data = json_decode($rawData, true); + if (preg_match('|' . $pattern . '|', $data[$fieldName]) > 0) { + return $this; + } + + $this->error( + "Field $fieldName did not match pattern $pattern in status data '$rawData'" + ); + + return $this; + } + /** * Expect that one of the processes in json status process list has a field with value that * matches the supplied pattern. @@ -167,7 +190,7 @@ class Response extends BaseResponse ); } foreach ($data['processes'] as $process) { - if (preg_match('|' . $pattern . '|', $process[$fieldName]) !== false) { + if (preg_match('|' . $pattern . '|', $process[$fieldName]) > 0) { return $this; } }