[php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6
| From: | Jakub Zelenka | Date: | Tue, 27 Oct 2026 17:01:25 +0000 |
| Subject: | [php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-142834@lists.php.net to get a copy of this message | ||
Author: Jakub Zelenka (bukka)
Date: 2026-10-27T18:00:56+01:00
Commit: https://github.com/php/php-src/commit/14714531022607642fde9c918d51697473785887
Raw diff: https://github.com/php/php-src/commit/14714531022607642fde9c918d51697473785887.diff
Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5:
Fix GH-24046: FPM worker stdio pipe fd closed twice
# Conflicts:
# NEWS
Changed paths:
A sapi/fpm/tests/gh24046-stdio-pipe-double-close.phpt
M NEWS
M sapi/fpm/fpm/fpm_children.c
Diff:
diff --git a/NEWS b/NEWS
index 099da538e969..ac066ed50cbb 100644
--- a/NEWS
+++ b/NEWS
@@ -31,6 +31,9 @@ PHP NEWS
. Fixed crash and stack memory disclosure in the worker output logging with
a pool name longer than the message prefix buffer or log_limit.
(Martin Mirchev)
+ . Fixed bug GH-24046 (FPM worker stdio pipe fd closed twice when a child
+ process outlives the worker, breaking a later worker's stdio).
+ (Ian P. Christian, ndossche)
- Hash:
. Fix GOST and Snefru digests of 512 MiB or more. (Martin Mirchev)
diff --git a/sapi/fpm/fpm/fpm_children.c b/sapi/fpm/fpm/fpm_children.c
index 285df91a9b69..4f86abd4038b 100644
--- a/sapi/fpm/fpm/fpm_children.c
+++ b/sapi/fpm/fpm/fpm_children.c
@@ -87,7 +87,11 @@ static void fpm_child_close(struct fpm_child_s *child, int in_event_loop) /* {{{
fpm_event_fire(&child->ev_stdout);
}
if (child->fd_stdout != -1) {
+ if (in_event_loop) {
+ fpm_event_del(&child->ev_stdout);
+ }
close(child->fd_stdout);
+ child->fd_stdout = -1;
}
}
@@ -97,7 +101,11 @@ static void fpm_child_close(struct fpm_child_s *child, int in_event_loop) /* {{{
fpm_event_fire(&child->ev_stderr);
}
if (child->fd_stderr != -1) {
+ if (in_event_loop) {
+ fpm_event_del(&child->ev_stderr);
+ }
close(child->fd_stderr);
+ child->fd_stderr = -1;
}
}
diff --git a/sapi/fpm/tests/gh24046-stdio-pipe-double-close.phpt
b/sapi/fpm/tests/gh24046-stdio-pipe-double-close.phpt
new file mode 100644
index 000000000000..af0c8bd0c6d8
--- /dev/null
+++ b/sapi/fpm/tests/gh24046-stdio-pipe-double-close.phpt
@@ -0,0 +1,57 @@
+--TEST--
+GH-24046 (FPM: worker stdio pipe fd closed twice when a child process outlives the worker)
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--FILE--
+<?php
+
+require_once "tester.inc";
+
+$cfg = <<<EOT
+[global]
+error_log = {{FILE:LOG}}
+[unconfined]
+listen = {{ADDR}}
+pm = static
+pm.max_children = 1
+pm.max_requests = 1
+catch_workers_output = yes
+decorate_workers_output = no
+EOT;
+
+$code = <<<'EOT'
+<?php
+/* dup() of the worker's stderr pipe that is inherited by the background process */
+$stderr = fopen('php://stderr', 'a');
+if (@fwrite($stderr, "log line\n") === false) {
+ echo "write to stderr failed";
+ exit;
+}
+if (isset($_GET['bg'])) {
+ exec('sleep 3 > /dev/null 2>&1 &');
+}
+echo "ok";
+EOT;
+
+$tester = new FPM\Tester($cfg, $code);
+$tester->start();
+$tester->expectLogStartNotices();
+/* The worker exits after this request while the background process still holds
+ * its stderr pipe open. The replacement worker gets the same pipe fd numbers. */
+$tester->request('bg=1')->expectBody('ok');
+/* Wait for the postponed free of the exited worker. */
+usleep(1500000);
+$tester->request()->expectBody('ok');
+$tester->terminate();
+$tester->expectNoLogPattern('/unable to (remove|read)/');
+$tester->close();
+
+?>
+Done
+--EXPECT--
+Done
+--CLEAN--
+<?php
+require_once "tester.inc";
+FPM\Tester::clean();
+?>