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:7
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: nick at cpanel dot net
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 07:01:29 2024 UTC