php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62033 php-fpm exits with status 0 on some failures to start
Submitted: 2012-05-14 22:00 UTC Modified: 2012-05-25 19:15 UTC
From: js at justinsamuel dot com Assigned: fat (profile)
Status: Closed Package: FPM related
PHP Version: 5.4.3 OS: Linux (Ubuntu 12.04)
Private report: No CVE-ID: None
 [2012-05-14 22:00 UTC] js at justinsamuel dot com
Description:
------------
When the php-fpm command fails because the 'user' value of a pool specifies a nonexistent user, php-fpm exits with 0 rather than a non-zero status. This is incorrect and causes problems with init scripts, for example.

This happens with both php 5.3 and 5.4.

Test script:
---------------
Snippet of a pool configuration which will trigger the bug:

[example.com]
user = fakeuser
...

Expected result:
----------------
php-fpm should exit with a non-zero status in all cases where there is an error which causes it to fail to start (including, but not limited to, nonexistent users).

Actual result:
--------------
$ php-fpm
[14-May-2012 14:39:40] ERROR: [pool example.com] cannot get uid for user 'fakeuser'
[14-May-2012 14:39:40] ERROR: FPM initialization failed
$ echo $?
0

Patches

bug62033-v2.patch (last revision 2012-05-25 08:48 UTC by fat@php.net)
bug62033.patch (last revision 2012-05-23 22:50 UTC by fat@php.net)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-15 02:09 UTC] laruence@php.net
-Assigned To: +Assigned To: fat
 [2012-05-23 07:36 UTC] fat@php.net
-Status: Assigned +Status: Feedback
 [2012-05-23 07:36 UTC] fat@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.


I can't reproduce the problem.

On my side with both up2date sources for 5.3 and 5.4:


root@dev:/home/fat/dev/php-git/php-5.4# ./sapi/fpm/php-fpm ; echo $?
[23-May-2012 09:32:03] ERROR: [pool direct] cannot get uid for user 'fatprout'
[23-May-2012 09:32:03] ERROR: FPM initialization failed
255

root@dev:/home/fat/dev/php-git/php-5.4# ./sapi/fpm/php-fpm ; echo $?
[23-May-2012 09:32:29] ERROR: [pool direct] cannot get gid for group 'fatprout'
[23-May-2012 09:32:29] ERROR: FPM initialization failed
255


which version of PHP are you using ? (sources from php.net you have compiled or 
a package from a distro ?)

Can you send me the result of 
php-fpm --version
php-fpm -tt

thx
 [2012-05-23 20:54 UTC] js at justinsamuel dot com
For simplicity here I'm going to focus on 5.3 instead of 5.4.

I've tried with the following:
* compiled from source (php.net tarballs) on Ubuntu 12.04
* compiled from source (php.net tarballs) on Debian 6
* Ubuntu 12.04's current php5-fpm package
* CentOS 6 with current php53u-fpm package from IUS

Here's the -tt info:

# /opt/test/php5.3/sbin/php-fpm --fpm-config /etc/php-test/fpm.conf -tt
[23-May-2012 13:07:26] NOTICE: [General]
[23-May-2012 13:07:26] NOTICE:  pid = /var/run/php5.3-test.pid
[23-May-2012 13:07:26] NOTICE:  error_log = /var/log/php5.3-test.log
[23-May-2012 13:07:26] NOTICE:  syslog.ident = php-fpm
[23-May-2012 13:07:26] NOTICE:  syslog.facility = 24
[23-May-2012 13:07:26] NOTICE:  log_level = unknown value
[23-May-2012 13:07:26] NOTICE:  emergency_restart_interval = 0s
[23-May-2012 13:07:26] NOTICE:  emergency_restart_threshold = 0
[23-May-2012 13:07:26] NOTICE:  process_control_timeout = 0s
[23-May-2012 13:07:26] NOTICE:  process.max = 0
[23-May-2012 13:07:26] NOTICE:  daemonize = yes
[23-May-2012 13:07:26] NOTICE:  rlimit_files = 0
[23-May-2012 13:07:26] NOTICE:  rlimit_core = 0
[23-May-2012 13:07:26] NOTICE:  events.mechanism = epoll
[23-May-2012 13:07:26] NOTICE:  
[23-May-2012 13:07:26] NOTICE: [example.com]
[23-May-2012 13:07:26] NOTICE:  prefix = undefined
[23-May-2012 13:07:26] NOTICE:  user = fakeuser
[23-May-2012 13:07:26] NOTICE:  group = fakegroup
[23-May-2012 13:07:26] NOTICE:  listen = /tmp/php5.3-test.sock
[23-May-2012 13:07:26] NOTICE:  listen.backlog = 128
[23-May-2012 13:07:26] NOTICE:  listen.owner = root
[23-May-2012 13:07:26] NOTICE:  listen.group = root
[23-May-2012 13:07:26] NOTICE:  listen.mode = 0700
[23-May-2012 13:07:26] NOTICE:  listen.allowed_clients = undefined
[23-May-2012 13:07:26] NOTICE:  pm = ondemand
[23-May-2012 13:07:26] NOTICE:  pm.max_children = 1
[23-May-2012 13:07:26] NOTICE:  pm.start_servers = 0
[23-May-2012 13:07:26] NOTICE:  pm.min_spare_servers = 0
[23-May-2012 13:07:26] NOTICE:  pm.max_spare_servers = 0
[23-May-2012 13:07:26] NOTICE:  pm.process_idle_timeout = 10
[23-May-2012 13:07:26] NOTICE:  pm.max_requests = 0
[23-May-2012 13:07:26] NOTICE:  pm.status_path = undefined
[23-May-2012 13:07:26] NOTICE:  ping.path = undefined
[23-May-2012 13:07:26] NOTICE:  ping.response = undefined
[23-May-2012 13:07:26] NOTICE:  access.log = undefined
[23-May-2012 13:07:26] NOTICE:  access.format = undefined
[23-May-2012 13:07:26] NOTICE:  slowlog = undefined
[23-May-2012 13:07:26] NOTICE:  request_slowlog_timeout = 0s
[23-May-2012 13:07:26] NOTICE:  request_terminate_timeout = 0s
[23-May-2012 13:07:26] NOTICE:  rlimit_files = 0
[23-May-2012 13:07:26] NOTICE:  rlimit_core = 0
[23-May-2012 13:07:26] NOTICE:  chroot = undefined
[23-May-2012 13:07:26] NOTICE:  chdir = undefined
[23-May-2012 13:07:26] NOTICE:  catch_workers_output = no
[23-May-2012 13:07:26] NOTICE:  security.limit_extensions = .php .phar
[23-May-2012 13:07:26] NOTICE:  
[23-May-2012 13:07:26] NOTICE: configuration file /etc/php-test/fpm.conf test is successful

Here's the version info for builds I've repeated this problem with. I haven't had any builds not show show this problem yet.

## on Ubuntu 12.04, built from source
# /opt/test/php5.3/sbin/php-fpm --version
PHP 5.3.13 (fpm-fcgi) (built: May 23 2012 12:21:32)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

## on Ubuntu 12.04, using distro's package
# php5-fpm --version
PHP 5.3.10-1ubuntu3.1 (fpm-fcgi) (built: May  4 2012 02:28:04)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

## on Debian 6, built from source
# /opt/test/php5.3/sbin/php-fpm --version
PHP 5.3.13 (fpm-fcgi) (built: May 23 2012 15:05:00)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

## on CentOS 6, using packages from IUS
# php-fpm --version
PHP 5.3.13 (fpm-fcgi) (built: May  8 2012 15:44:17)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

As a sanity check, I've repeated the problem again on all of the above versions with the same config. They all show the same error but exit with 0.
 [2012-05-23 22:10 UTC] fat@php.net
This is strange ...

can you please test the following patch and see if exit code is 42 on error ?


diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c
index 95a7623..62c1b69 100644
--- a/sapi/fpm/fpm/fpm_main.c
+++ b/sapi/fpm/fpm/fpm_main.c
@@ -1803,7 +1803,8 @@ consult the installation file that came with this 
distribution, or visit \n\
        }

        if (0 > fpm_init(argc, argv, fpm_config ? fpm_config : CGIG(fpm_config), 
fpm_prefix, fpm_pid, test_conf, php_allow_to_run_as_root)) {
-               return FAILURE;
+//             return FAILURE;
+               exit(42);
        }

        fpm_is_running = 1;


thx
++ Jerome
 [2012-05-23 22:50 UTC] fat@php.net
The following patch has been added/updated:

Patch Name: bug62033.patch
Revision:   1337813451
URL:        https://bugs.php.net/patch-display.php?bug=62033&patch=bug62033.patch&revision=1337813451
 [2012-05-23 22:51 UTC] fat@php.net
-Status: Feedback +Status: Analyzed
 [2012-05-23 22:51 UTC] fat@php.net
-Status: Analyzed +Status: Feedback
 [2012-05-23 22:51 UTC] fat@php.net
I've attached a real patch to this bug report.

Can you please test it ?

thx
++ Jerome
 [2012-05-24 00:08 UTC] js at justinsamuel dot com
-Status: Feedback +Status: Assigned
 [2012-05-24 00:08 UTC] js at justinsamuel dot com
I've tested this patch with the current PHP-5.3. The problem still persists. 

A quick look with strace makes it seem that a child process is exiting with the status that is expected from the patch (78) but its parent is not.

# rm -f /tmp/php-fpm.strace.*
# strace -o /tmp/php-fpm.strace -ff -f /opt/test/php5.3/sbin/php-fpm --fpm-config /root/php-test/fpm.conf 
[23-May-2012 18:54:57] ERROR: [pool example.com] cannot get uid for user 'fakeuser'
[23-May-2012 18:54:57] ERROR: FPM initialization failed
# echo $?
0
# ll /tmp/php-fpm.strace.*
-rw-r--r-- 1 root root 25282 May 23 18:54 /tmp/php-fpm.strace.996
-rw-r--r-- 1 root root  4125 May 23 18:54 /tmp/php-fpm.strace.997
# grep -B 2 exit /tmp/php-fpm.strace.*
/tmp/php-fpm.strace.996-clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f2e60ff19d0) = 997
/tmp/php-fpm.strace.996-munmap(0x7f2e60f60000, 323584)          = 0
/tmp/php-fpm.strace.996:exit_group(0)                           = ?
--
/tmp/php-fpm.strace.997-write(3, "[23-May-2012 18:54:57] ERROR: FP"..., 56) = 56
/tmp/php-fpm.strace.997-write(2, "[23-May-2012 18:54:57] ERROR: FP"..., 56) = 56
/tmp/php-fpm.strace.997:exit_group(78)                          = ?

Thanks,
Justin
 [2012-05-25 08:48 UTC] fat@php.net
The following patch has been added/updated:

Patch Name: bug62033-v2.patch
Revision:   1337935697
URL:        https://bugs.php.net/patch-display.php?bug=62033&patch=bug62033-v2.patch&revision=1337935697
 [2012-05-25 08:52 UTC] fat@php.net
-Status: Assigned +Status: Feedback
 [2012-05-25 08:52 UTC] fat@php.net
Hi again,

here is a new revision of the patch. Now, when daemonized, the calling process 
register 2 signal handler for USR1 and USR2 just before forking the master 
process. After initialization ends on the master process, it sends USR1 if 
successful or USR2 otherwise to the calling process. On USR1 signal, the calling 
process exits with 0, on USR2 it exists with error 78 (EX_CONFIG) and if does 
not receive anything, there's a 10 seconds timeout to exit with code 70 
(EX_SOFTWARE).

Can you please test it ?

thx
++ Jerome
 [2012-05-25 16:19 UTC] js at justinsamuel dot com
With the v2 patch this is working as expected:

# /opt/test/php5.3/sbin/php-fpm --fpm-config /root/php-test/fpm.conf
[25-May-2012 11:08:17] ERROR: [pool example.com] cannot get uid for user 'fakeuser'
[25-May-2012 11:08:17] ERROR: FPM initialization failed
# echo $?
78

Thanks!

Justin
 [2012-05-25 19:15 UTC] fat@php.net
Automatic comment on behalf of fat
Revision: http://git.php.net/?p=php-src.git;a=commit;h=bf9120ecae6e4653dbb5a1b0576f0b163afd6846
Log: - Fixed bug #62033 (php-fpm exits with status 0 on some failures to start)
 [2012-05-25 19:15 UTC] fat@php.net
Automatic comment on behalf of fat
Revision: http://git.php.net/?p=php-src.git;a=commit;h=c2f33fb1293cbcdc94daefb8583ca13e98b5c826
Log: - Fixed bug #62033 (php-fpm exits with status 0 on some failures to start)
 [2012-05-25 19:15 UTC] fat@php.net
Automatic comment on behalf of fat
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a28fe034f2d5253e0fbefafc6a7938df9db7319e
Log: - Fixed bug #62033 (php-fpm exits with status 0 on some failures to start).
 [2012-05-25 19:15 UTC] fat@php.net
-Status: Feedback +Status: Closed
 [2012-05-25 19:15 UTC] fat@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2012-05-26 16:49 UTC] fat@php.net
Automatic comment on behalf of fat
Revision: http://git.php.net/?p=php-src.git;a=commit;h=0298b92b69e5637e8d151790ad6369f7980a406a
Log: - Fixed bug #62033 (USR2 signal was sent even if not catch when daemonize and an error occured)
 [2012-05-26 16:49 UTC] fat@php.net
Automatic comment on behalf of fat
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e052da3a6bc353636fa4bf9cb488573c50adf9a0
Log: Fixed bug #62033 (USR2 signal was sent even if not catch when daemonize and an error occured)
 [2012-05-26 16:49 UTC] fat@php.net
Automatic comment on behalf of fat
Revision: http://git.php.net/?p=php-src.git;a=commit;h=0225300b7067f4396e2bce57d549b8da9126c33e
Log: Fixed bug #62033 (USR2 signal was sent even if not catch when daemonize and an error occured)
 [2012-05-29 10:27 UTC] ab@php.net
Automatic comment on behalf of fat
Revision: http://git.php.net/?p=php-src.git;a=commit;h=0298b92b69e5637e8d151790ad6369f7980a406a
Log: - Fixed bug #62033 (USR2 signal was sent even if not catch when daemonize and an error occured)
 [2012-05-29 10:27 UTC] ab@php.net
Automatic comment on behalf of fat
Revision: http://git.php.net/?p=php-src.git;a=commit;h=bf9120ecae6e4653dbb5a1b0576f0b163afd6846
Log: - Fixed bug #62033 (php-fpm exits with status 0 on some failures to start)
 [2012-05-29 10:27 UTC] ab@php.net
Automatic comment on behalf of fat
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e052da3a6bc353636fa4bf9cb488573c50adf9a0
Log: Fixed bug #62033 (USR2 signal was sent even if not catch when daemonize and an error occured)
 [2012-05-29 10:27 UTC] ab@php.net
Automatic comment on behalf of fat
Revision: http://git.php.net/?p=php-src.git;a=commit;h=c2f33fb1293cbcdc94daefb8583ca13e98b5c826
Log: - Fixed bug #62033 (php-fpm exits with status 0 on some failures to start)
 [2012-07-24 23:35 UTC] rasmus@php.net
Automatic comment on behalf of fat
Revision: http://git.php.net/?p=php-src.git;a=commit;h=0225300b7067f4396e2bce57d549b8da9126c33e
Log: Fixed bug #62033 (USR2 signal was sent even if not catch when daemonize and an error occured)
 [2012-07-24 23:35 UTC] rasmus@php.net
Automatic comment on behalf of fat
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a28fe034f2d5253e0fbefafc6a7938df9db7319e
Log: - Fixed bug #62033 (php-fpm exits with status 0 on some failures to start).
 [2013-11-17 09:32 UTC] laruence@php.net
Automatic comment on behalf of fat
Revision: http://git.php.net/?p=php-src.git;a=commit;h=0225300b7067f4396e2bce57d549b8da9126c33e
Log: Fixed bug #62033 (USR2 signal was sent even if not catch when daemonize and an error occured)
 [2013-11-17 09:32 UTC] laruence@php.net
Automatic comment on behalf of fat
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a28fe034f2d5253e0fbefafc6a7938df9db7319e
Log: - Fixed bug #62033 (php-fpm exits with status 0 on some failures to start).
 [2014-10-07 23:24 UTC] stas@php.net
Automatic comment on behalf of fat
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=e052da3a6bc353636fa4bf9cb488573c50adf9a0
Log: Fixed bug #62033 (USR2 signal was sent even if not catch when daemonize and an error occured)
 [2014-10-07 23:24 UTC] stas@php.net
Automatic comment on behalf of fat
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=0298b92b69e5637e8d151790ad6369f7980a406a
Log: - Fixed bug #62033 (USR2 signal was sent even if not catch when daemonize and an error occured)
 [2014-10-07 23:24 UTC] stas@php.net
Automatic comment on behalf of fat
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=c2f33fb1293cbcdc94daefb8583ca13e98b5c826
Log: - Fixed bug #62033 (php-fpm exits with status 0 on some failures to start)
 [2014-10-07 23:24 UTC] stas@php.net
Automatic comment on behalf of fat
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=bf9120ecae6e4653dbb5a1b0576f0b163afd6846
Log: - Fixed bug #62033 (php-fpm exits with status 0 on some failures to start)
 [2014-10-07 23:35 UTC] stas@php.net
Automatic comment on behalf of fat
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=e052da3a6bc353636fa4bf9cb488573c50adf9a0
Log: Fixed bug #62033 (USR2 signal was sent even if not catch when daemonize and an error occured)
 [2014-10-07 23:35 UTC] stas@php.net
Automatic comment on behalf of fat
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=0298b92b69e5637e8d151790ad6369f7980a406a
Log: - Fixed bug #62033 (USR2 signal was sent even if not catch when daemonize and an error occured)
 [2014-10-07 23:35 UTC] stas@php.net
Automatic comment on behalf of fat
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=c2f33fb1293cbcdc94daefb8583ca13e98b5c826
Log: - Fixed bug #62033 (php-fpm exits with status 0 on some failures to start)
 [2014-10-07 23:35 UTC] stas@php.net
Automatic comment on behalf of fat
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=bf9120ecae6e4653dbb5a1b0576f0b163afd6846
Log: - Fixed bug #62033 (php-fpm exits with status 0 on some failures to start)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC