Search code examples
apachesymfonysessioncrashsymfony3

Apache crashing when doing concurrent requests with Symfony dev mode


I'm making a symfony 3.4 application as REST service (so I have installed the usual JMS Serializer, FoSRest and lexik/jwt-authentication-bundle) and testing it on XAMPP (Windows 10).
When i make XHR requests through my frontend application using app_dev.php as endpoint it (very) often happens that Apache crashes when making 2+ requests at the same time.
Reading here and there it looks like that this issue is often caused by an attempt to write on the session file since symfony default session handler is session.handler.native_file.
So i first tried to put null (which, according to the documentation, uses native PHP session handler), this made the crashes happen less often but didn't fix the issue completely
Then i tried using Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler which made the crashes happen even less than before, but there's still the occasional crash

Now that i'm using a database as session handler though i'm noticing that no session is being written on the database when i make XHR requests (While it does if i open a normal web page served by the application), which shouldn't surprise me since I set my security.yml such that the REST routes must be stateless, and yet toying with the handler_id configuration influences how often my apache crashes

The same thing doesn't happen if I open multiple web pages served by the same application, nor it happens if I use the production endpoint (app.php).

Is there any way to fix this completely?

EDIT: As requested

Can you add the apache error logs and php error logs?

It just repeats like this for each time it restarted. I have noticed this line: AH00428: Parent: child process 29076 exited with status 3221226356 -- Restarting. which might be interesting investigating upon

[Sun Dec 17 00:39:58.548676 2017] [mpm_winnt:notice] [pid 17564:tid 532] AH00428: Parent: child process 22856 exited with status 3221226356 -- Restarting.
[Sun Dec 17 00:39:59.544151 2017] [ssl:warn] [pid 17564:tid 532] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sun Dec 17 00:39:59.740710 2017] [mpm_winnt:notice] [pid 17564:tid 532] AH00455: Apache/2.4.26 (Win32) OpenSSL/1.0.2l PHP/7.1.7 configured -- resuming normal operations
[Sun Dec 17 00:39:59.740710 2017] [mpm_winnt:notice] [pid 17564:tid 532] AH00456: Apache Lounge VC14 Server built: Jun 15 2017 12:39:41
[Sun Dec 17 00:39:59.740710 2017] [core:notice] [pid 17564:tid 532] AH00094: Command line: 'c:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Sun Dec 17 00:39:59.746705 2017] [mpm_winnt:notice] [pid 17564:tid 532] AH00418: Parent: Created child process 29076
[Sun Dec 17 00:40:01.201423 2017] [ssl:warn] [pid 29076:tid 592] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sun Dec 17 00:40:01.414295 2017] [ssl:warn] [pid 29076:tid 592] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sun Dec 17 00:40:01.455312 2017] [mpm_winnt:notice] [pid 29076:tid 592] AH00354: Child: Starting 150 worker threads.
[Sun Dec 17 00:40:17.006680 2017] [mpm_winnt:notice] [pid 17564:tid 532] AH00428: Parent: child process 29076 exited with status 3221226356 -- Restarting.
[Sun Dec 17 00:40:17.371667 2017] [ssl:warn] [pid 17564:tid 532] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sun Dec 17 00:40:17.403690 2017] [mpm_winnt:notice] [pid 17564:tid 532] AH00455: Apache/2.4.26 (Win32) OpenSSL/1.0.2l PHP/7.1.7 configured -- resuming normal operations
[Sun Dec 17 00:40:17.403690 2017] [mpm_winnt:notice] [pid 17564:tid 532] AH00456: Apache Lounge VC14 Server built: Jun 15 2017 12:39:41
[Sun Dec 17 00:40:17.403690 2017] [core:notice] [pid 17564:tid 532] AH00094: Command line: 'c:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Sun Dec 17 00:40:17.409694 2017] [mpm_winnt:notice] [pid 17564:tid 532] AH00418: Parent: Created child process 24332
[Sun Dec 17 00:40:18.667139 2017] [ssl:warn] [pid 24332:tid 524] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sun Dec 17 00:40:18.858441 2017] [ssl:warn] [pid 24332:tid 524] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sun Dec 17 00:40:18.895469 2017] [mpm_winnt:notice] [pid 24332:tid 524] AH00354: Child: Starting 150 worker threads.
[Sun Dec 17 00:40:20.972550 2017] [mpm_winnt:notice] [pid 17564:tid 532] AH00428: Parent: child process 24332 exited with status 3221226356 -- Restarting.
[Sun Dec 17 00:40:21.481091 2017] [ssl:warn] [pid 17564:tid 532] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sun Dec 17 00:40:21.513627 2017] [mpm_winnt:notice] [pid 17564:tid 532] AH00455: Apache/2.4.26 (Win32) OpenSSL/1.0.2l PHP/7.1.7 configured -- resuming normal operations
[Sun Dec 17 00:40:21.513627 2017] [mpm_winnt:notice] [pid 17564:tid 532] AH00456: Apache Lounge VC14 Server built: Jun 15 2017 12:39:41
[Sun Dec 17 00:40:21.513627 2017] [core:notice] [pid 17564:tid 532] AH00094: Command line: 'c:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Sun Dec 17 00:40:21.519144 2017] [mpm_winnt:notice] [pid 17564:tid 532] AH00418: Parent: Created child process 27440
[Sun Dec 17 00:40:22.991094 2017] [ssl:warn] [pid 27440:tid 552] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sun Dec 17 00:40:23.266105 2017] [ssl:warn] [pid 27440:tid 552] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sun Dec 17 00:40:23.301132 2017] [mpm_winnt:notice] [pid 27440:tid 552] AH00354: Child: Starting 150 worker threads.

When you say apache crash means that you have to start apache again, or you just get an error? Which error do you get?

I Just get the usual application crashed window saying "Apache has stopped working", if i click "Close the application" it restarts by itself and the request that caused the crash simply fails with no status code or error message (which is expected since the connection with the server stopped). As you can see there's no specific error in the logs except for that status code

How you have setup apache and php mod_apache, php-fpm? Which apache server limits do you have, how many php workers?

I'm not sure how to answer this question, i'm using stock apache and php from the XAMPP package with no edits to the configuration. I can tell you php is loaded as apache handler, so no CGI or FastCGI. Anyways on simple pages or using production mode in Symfony it works fine

NEWS:

  1. I have discovered that since i was doing CORS requests it was creating a session file for each request, i fixed that and it slightly improved my issue, but it's still there

  2. I have tried using redis as session handler for PHP but it actually made things worse

  3. I have made a simple test where i called the same page (which uses session) 1000 times, it works fine as long as i put session_write_close(); at the end, otherwise it crashes


Solution

  • As stated in my last comment, I tried using FastCGI and it fixed the issue. https://blog.tiger-workshop.com/fix-various-apache-crashes-on-windows/

    On this page there are 2 suggestions for the error i was receiving AH00428: Parent: child process 29076 exited with status 3221226356 -- Restarting. One fix is to add the following lines to httpd.conf

    <IfModule mpm_winnt_module>
       ThreadStackSize 8388608
    </IfModule>
    

    But it didn't work. The second fix is related to a bug that happens in windows when using PHP as Apache Handler https://github.com/vlucas/phpdotenv/issues/76 so i switched to FastCGI as suggested.
    These instructions are more specific to XAMPP than the ones posted in the link above. You need to edit the file xampp\apache\conf\extra\httpd-xampp.conf

    Comment the following lines

    #
    # PHP-Module setup
    #
    #LoadFile "C:/xampp/php/php7ts.dll"
    #LoadFile "C:/xampp/php/libpq.dll"
    #LoadModule php7_module "C:/xampp/php/php7apache2_4.dll"
    #
    #<FilesMatch "\.php$">
    #    SetHandler application/x-httpd-php
    #</FilesMatch>
    #<FilesMatch "\.phps$">
    #    SetHandler application/x-httpd-php-source
    #</FilesMatch>
    [...] (This one is further down in the file)
    # 
    #<IfModule php7_module>
    #    PHPINIDir "C:/xampp/php"
    #</IfModule>
    

    And add these lines

    LoadModule fcgid_module modules/mod_fcgid.so
    
    <IfModule fcgid_module>
       FcgidMaxProcesses 300
       FcgidMaxProcessesPerClass 300
    
       FcgidOutputBufferSize 65536
       FcgidConnectTimeout 10
       FcgidProcessLifeTime 0
       FcgidMaxRequestsPerProcess 0
       FcgidMinProcessesPerClass 0
       FcgidFixPathinfo 0
       FcgidProcessLifeTime 0
       FcgidZombieScanInterval 20
       FcgidMaxRequestLen 536870912
       FcgidIOTimeout 120
       FcgidTimeScore 3
    
       FcgidPassHeader Authorization
    
       FcgidInitialEnv PHPRC "C:\\xampp\\php"
       FcgidInitialEnv PATH "C:\\xampp\\php;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;"
       FcgidInitialEnv SystemRoot "C:\\Windows"
       FcgidInitialEnv SystemDrive "C:"
       FcgidInitialEnv TEMP "C:\\xampp\\tmp"
       FcgidInitialEnv TMP "C:\\xampp\\tmp"
       FcgidInitialEnv windir "C:\\Windows"
    
       DirectoryIndex index.html index.htm index.php
    
       <Files ~ "\.php$">
          Options Indexes FollowSymLinks ExecCGI
          AddHandler fcgid-script .php
          FcgidWrapper "C:/xampp/php/php-cgi.exe" .php
       </Files>
    </IfModule>