|  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:7 of 7 (100.0%)
Same Version:6 (85.7%)
Same OS:6 (85.7%)
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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: nick at cpanel dot net
New email:
PHP Version: OS:


 [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-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 20:01:29 2024 UTC