|  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
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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
4 + 42 = ?
Subscribe to this entry?

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

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- = | 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.


Add a Patch

Pull Requests

Add a Pull Request


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.

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat May 08 08:01:24 2021 UTC