Skip to content

Commit 9afd16b

Browse files
committed
Fix GH-9754: SaltStack hangs when running php-fpm 8.1.11
SaltStack uses Python subprocess and redirects stderr to stdout which is then piped to the returned output. If php-fpm starts in daemonized mode, it should close stderr. However a fix introduced in GH-8913 keeps stderr around so it can be later restored. That causes the issue reported in GH-9754. The solution is to keep stderr around only when php-fpm runs in foreground as the issue is most likely visible only there. Basically there is no need to restore stderr when php-fpm is daemonized.
1 parent 45e224c commit 9afd16b

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

sapi/fpm/fpm/fpm_conf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ static int fpm_conf_post_process(int force_daemon) /* {{{ */
12821282
fpm_evaluate_full_path(&fpm_global_config.error_log, NULL, PHP_LOCALSTATEDIR, 0);
12831283
}
12841284

1285-
if (0 > fpm_stdio_save_original_stderr()) {
1285+
if (!fpm_global_config.daemonize && 0 > fpm_stdio_save_original_stderr()) {
12861286
return -1;
12871287
}
12881288

sapi/fpm/fpm/fpm_stdio.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ int fpm_stdio_init_final(void)
7474

7575
int fpm_stdio_save_original_stderr(void)
7676
{
77-
/* php-fpm loses STDERR fd after call of the fpm_stdio_init_final(). Check #8555. */
77+
/* STDERR fd gets lost after callingfpm_stdio_init_final() (check GH-8555) so it can be saved.
78+
* It should be used only when PHP-FPM is not daemonized otherwise it might break some
79+
* applications (e.g. GH-9754). */
7880
zlog(ZLOG_DEBUG, "saving original STDERR fd: dup()");
7981
fd_stderr_original = dup(STDERR_FILENO);
8082
if (0 > fd_stderr_original) {
@@ -87,7 +89,7 @@ int fpm_stdio_save_original_stderr(void)
8789

8890
int fpm_stdio_restore_original_stderr(int close_after_restore)
8991
{
90-
/* php-fpm loses STDERR fd after call of the fpm_stdio_init_final(). Check #8555. */
92+
/* Restore original STDERR fd if it was previously saved. */
9193
if (-1 != fd_stderr_original) {
9294
zlog(ZLOG_DEBUG, "restoring original STDERR fd: dup2()");
9395
if (0 > dup2(fd_stderr_original, STDERR_FILENO)) {
@@ -98,9 +100,6 @@ int fpm_stdio_restore_original_stderr(int close_after_restore)
98100
close(fd_stderr_original);
99101
}
100102
}
101-
} else {
102-
zlog(ZLOG_DEBUG, "original STDERR fd is not restored, maybe function is called from a child: dup2()");
103-
return -1;
104103
}
105104

106105
return 0;

0 commit comments

Comments
 (0)