Bug #72935 [NEW]: ONDEMAND: Race condition causes incoming connections hang
| From: | nick at cpanel dot net | Date: | Wed, 24 Aug 2016 20:13:03 +0000 |
| Subject: | Bug #72935 [NEW]: ONDEMAND: Race condition causes incoming connections hang | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-203526@lists.php.net to get a copy of this message | ||
From: nick at cpanel dot net
Operating system: Linux
PHP version: 5.6.25
Package: FPM related
Bug Type: Bug
Bug description:ONDEMAND: Race condition causes incoming connections hang
Description:
------------
TLDR; If two clients connect to PHP-FPM in ondemand mode on the same
unix socket before accept() happens in the child only one gets
accept()ed.
PHP-FPM uses epoll() on linux to detect when an incoming connection
needs to be handled. With ONDEMAND, when the epoll() has an EPOLLIN
event it triggers
sapi/fpm/fpm/fpm_process_ctl.c.:fpm_pctl_on_socket_accept which will
either spawn a child or rely on an idle child to do the accept()
If a second connect() happens from another client before the first one
is accept()ed the state will never change so the second client will hang
until the the next state change on the listening socket. See:
https://lkml.org/lkml/2011/11/17/234
sapi/fpm/fpm/fpm_children.c: fpm_event_set(wp->ondemand_event,
wp->listening_socket, FPM_EV_READ | FPM_EV_EDGE,
fpm_pctl_on_socket_accept, wp);
sapi/fpm/fpm/events/epoll.c: if (ev->flags & FPM_EV_EDGE) {
sapi/fpm/fpm/events/epoll.c- e.events = e.events | EPOLLET;
sapi/fpm/fpm/events/epoll.c- }
Expected result:
----------------
Both clients get accept()ed
Actual result:
--------------
The first client gets accept()ed and the second client hangs waiting for
php-fpm to respond.
--
Edit bug report at https://bugs.php.net/bug.php?id=72935&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72935&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72935&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72935&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=72935&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=72935&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=72935&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=72935&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=72935&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=72935&r=support
Expected behavior: https://bugs.php.net/fix.php?id=72935&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=72935&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=72935&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=72935&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72935&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=72935&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=72935&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=72935&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72935&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=72935&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=72935&r=mysqlcfg