#40738 [NEW]: php fastcgi on windows hangs if 'reuse-connnections' is enabled

Ask a Question related to PHP Bugs, Design and Development.

  1. #1

    Default #40738 [NEW]: php fastcgi on windows hangs if 'reuse-connnections' is enabled

    From: sriram dot natarajan at sun dot com
    Operating system: windows
    PHP version: 5.2.1
    PHP Bug Type: *General Issues
    Bug description: php fastcgi on windows hangs if 'reuse-connnections' is enabled

    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;
    }
    ---------------------------------------------------------------



    --
    Edit bug report at [url]http://bugs.php.net/?id=40738&edit=1[/url]
    --
    Try a CVS snapshot (PHP 4.4): [url]http://bugs.php.net/fix.php?id=40738&r=trysnapshot44[/url]
    Try a CVS snapshot (PHP 5.2): [url]http://bugs.php.net/fix.php?id=40738&r=trysnapshot52[/url]
    Try a CVS snapshot (PHP 6.0): [url]http://bugs.php.net/fix.php?id=40738&r=trysnapshot60[/url]
    Fixed in CVS: [url]http://bugs.php.net/fix.php?id=40738&r=fixedcvs[/url]
    Fixed in release: [url]http://bugs.php.net/fix.php?id=40738&r=alreadyfixed[/url]
    Need backtrace: [url]http://bugs.php.net/fix.php?id=40738&r=needtrace[/url]
    Need Reproduce Script: [url]http://bugs.php.net/fix.php?id=40738&r=needscript[/url]
    Try newer version: [url]http://bugs.php.net/fix.php?id=40738&r=oldversion[/url]
    Not developer issue: [url]http://bugs.php.net/fix.php?id=40738&r=support[/url]
    Expected behavior: [url]http://bugs.php.net/fix.php?id=40738&r=notwrong[/url]
    Not enough info: [url]http://bugs.php.net/fix.php?id=40738&r=notenoughinfo[/url]
    Submitted twice: [url]http://bugs.php.net/fix.php?id=40738&r=submittedtwice[/url]
    register_globals: [url]http://bugs.php.net/fix.php?id=40738&r=globals[/url]
    PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=40738&r=php3[/url]
    Daylight Savings: [url]http://bugs.php.net/fix.php?id=40738&r=dst[/url]
    IIS Stability: [url]http://bugs.php.net/fix.php?id=40738&r=isapi[/url]
    Install GNU Sed: [url]http://bugs.php.net/fix.php?id=40738&r=gnused[/url]
    Floating point limitations: [url]http://bugs.php.net/fix.php?id=40738&r=float[/url]
    No Zend Extensions: [url]http://bugs.php.net/fix.php?id=40738&r=nozend[/url]
    MySQL Configuration Error: [url]http://bugs.php.net/fix.php?id=40738&r=mysqlcfg[/url]
    sriram dot natarajan at sun dot com Guest

  2. Similar Questions and Discussions

    1. #40665 [NEW]: DOM/EXSLT not enabled in Windows binaries
      From: bat at flurf dot net Operating system: Windows XP PHP version: 4CVS-2007-02-28 (snap) PHP Bug Type: XSLT related Bug...
    2. GraphViz in Windows hangs
      I am using perl in windows and want to use the GraphViz module to interface with GraphViz. When I run any simple example program, a cmd prompt...
    3. apache hangs when warnings are enabled in mod_perl
      Hi, I'm running Apache 1.3.27, mod_perl 1.26, and mysql 3.23. I've got a strange problem that is caused by enabling warnings in my code. I've...
    4. Apache/FastCGI with Ruby on Windows
      I've compiled fastcgi support into my windows version of Ruby (1.6.8), and I've compiled Apache 2.0 for Windows with support for the fastcgi...
    5. Windows Explorer Hangs
      I have done all the SP1 and updates but yet when I go to close folders the folders will not close and CPU util. goes to near 100%. Any suggestions...
  3. #2

    Default #40738 [Opn->Asn]: php fastcgi on windows hangs if 'reuse-connnections' is enabled

    ID: 40738
    Updated by: [email]tony2001@php.net[/email]
    Reported By: sriram dot natarajan at sun dot com
    -Status: Open
    +Status: Assigned
    -Bug Type: *General Issues
    +Bug Type: CGI related
    Operating System: windows
    PHP Version: 5.2.1
    -Assigned To:
    +Assigned To: dmitry


    Previous Comments:
    ------------------------------------------------------------------------

    [2007-03-06 08:37:00] 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;
    }
    ---------------------------------------------------------------




    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40738&edit=1[/url]
    tony2001@php.net Guest

  4. #3

    Default #40738 [Asn->Fbk]: php fastcgi on windows hangs if 'reuse-connnections' is enabled

    ID: 40738
    Updated by: [email]dmitry@php.net[/email]
    Reported By: sriram dot natarajan at sun dot com
    -Status: Assigned
    +Status: Feedback
    Bug Type: CGI related
    Operating System: windows
    PHP Version: 5.2.1
    Assigned To: dmitry
    New Comment:

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


    Previous Comments:
    ------------------------------------------------------------------------

    [2007-03-06 08:37:00] 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;
    }
    ---------------------------------------------------------------




    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40738&edit=1[/url]
    dmitry@php.net Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139