php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72935 ONDEMAND: Race condition causes incoming connections hang
Submitted: 2016-08-24 20:12 UTC Modified: 2016-08-24 21:56 UTC
Votes:6
Avg. Score:4.7 ± 0.7
Reproduced:6 of 6 (100.0%)
Same Version:6 (100.0%)
Same OS:5 (83.3%)
From: nick at cpanel dot net Assigned:
Status: Open Package: FPM related
PHP Version: 5.6.25 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2016-08-24 20:12 UTC] nick at cpanel dot net
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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-24 21:56 UTC] nick at cpanel dot net
I found a duplicate bug in the system after I submitted this.

69724
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Jun 20 19:01:26 2019 UTC