php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40738 php fastcgi on windows hangs if 'reuse-connnections' is enabled
Submitted: 2007-03-06 08:37 UTC Modified: 2007-03-14 01:00 UTC
From: sriram dot natarajan at sun dot com Assigned: dmitry (profile)
Status: No Feedback Package: CGI/CLI related
PHP Version: 5.2.1 OS: windows
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-03-06 08:37 UTC] sriram dot natarajan at sun dot com
Description:
------------
currently, when we use Php 5.2.x as 'fastcgi' plugin with web server + fastcgi support and enable 'reuse-connection' , then the php processes does not shutdown correctly. 

here is the issue

 During shutdown, the plugin sends TERM signal to the PHP primordial which in turn sends TERM to its child processes. In case of reuse-connection=1, the child PHP process which has served the request, would be waiting in "read" (within a "while" loop). If, at this time, it receives a TERM signal, then this read gets interrupted and the signal handler gets executed which sets the variable "in_shutdown" to true. Since "read" is inside the loop and there is no check for this in_shutdown variable within the loop, the PHP process continues to wait in "read".

The following change in the PHP code fixed this issue.

File: <php src dir>/sapi/cgi/fastcgi.c
---------------------------------------------------------------
static inline ssize_t safe_read(fcgi_request *req, const void *buf, size_t count)
{
        int    ret;
        size_t n = 0;

        do {
                ret = read(req->fd, ((char*)buf)+n, count-n);
                // This check is needed to avoid looping during shutdown.
+                if(in_shutdown) { // missing code
+                    return -1; 
                } else if (ret > 0) {
                        n += ret;
                } else if (ret == 0 && errno == 0) {
                        return n;
                } else if (ret <= 0 && errno != 0 && errno != EINTR) {
                        return ret;
                }
        } while (n != count);
        return n;
}
---------------------------------------------------------------



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-03-06 13:14 UTC] dmitry@php.net
'reuse-connection' is probably some setting of web-server or FastCGI plugin, but I don't understand which web-server and which FastCGI plugin do you mean.

Your patch is not correct, because PHP must finish request processing and die only after that. This allows graceful restart without request dropping. 

In case if web-server or FastCGI plugin really decide drop requests, it must just close connection to PHP and it will exit from safe_read() loop because of broken pipe.
 [2007-03-14 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 06:01:29 2024 UTC