php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59506 APC crashes Apache on shutdown (or graceful restart)
Submitted: 2010-11-12 05:53 UTC Modified: 2010-11-17 05:29 UTC
From: Brian dot White at foxfire74 dot com Assigned: pajoye (profile)
Status: Closed Package: APC (PECL)
PHP Version: 5.3.2 OS: Windows XP
Private report: No CVE-ID: None
 [2010-11-12 05:53 UTC] Brian dot White at foxfire74 dot com
Description:
------------
PHP Version 5.3.3 (cannot select it in phpversion here)

The Apache service crashes and does not exit cleanly on shutdown (or graceful restart).  Instead, I receive "System error 1067 has occurred. The process terminated unexpectedly" and an error in the event log.

If attempting to restart, the main Apache process crashes (as well as the one Windows child) and the restart does NOT occur.

IMPORTANT: I used php_apc.pdb from 21 July 2010 to generate the backtrace since that was all I could find, so the function name/offsets for php_apc.dll are not accurate.  The .pdbs and .dlls match for everything else.

The CloseHandle() call than is faulting is likely in the apc_fcntl_destroy function of apc_fcntl_win32.c.

74 void apc_fcntl_destroy(int fd)
75 {
76     CloseHandle((HANDLE)fd);
77 }

The only other CloseHandle() call is in the apc_restat() function of apc.c; however, it has checks for a valid file handle before continuing.

Reproduce code:
---------------
From the command line, run: NET STOP Apache2.2 (or  httpd.exe -k restart)


Expected result:
----------------
Apache stops (or restarts)

Actual result:
--------------
Thread 0 - System ID 4008
Entry point   httpd+21d9 
Create time   11/11/2010 7:51:32 AM 
Time spent in user mode   0 Days 0:0:3.605 
Time spent in kernel mode   0 Days 0:0:0.991 

Function     Arg 1     Arg 2     Arg 3   Source 
ntdll!KiRaiseUserExceptionDispatcher+37     7c90cffa     7c809c2b     00000630    
ntdll!KiFastSystemCall+3     7c809c2b     00000630     013f8918    
ntdll!NtClose+c     00000630     013f8918     018ab1eb    
kernel32!CloseHandle+51     00000630     018a5170     00000630    
php_apc!apc_fcntl_unlock+6cb     00000001     00000021     0138d578    [NOT ACCURATE!!! (MISMATCHED SYMBOL FILE)]
php5ts!module_destructor+4a     013f8918     00a823e5     0138d578    
php5ts!zend_hash_clean+112     0138d578     0138d578     009f1f5e    
php5ts!zend_hash_graceful_reverse_destroy+15     00f6f1c0     0138f6c0     0138d578    
php5ts!zend_shutdown+2e     0138d578     0138d578     005aa230    
php5ts!php_module_shutdown+2f     0138d578     00000000     00000000    
php5ts!php_module_shutdown_wrapper+f     009d7098     6eec8353     00000000    
php5apache2_2!zm_info_apache+c6b     00000000     6eec8827     6eec87f0    
libapr_1!apr_pool_cleanup_run+43     6eec87f0     006a35a8     00401cc9    
libapr_1!apr_pool_clear+37     00000000     00000000     00000000    

In httpd__PID__5748__Date__11_12_2010__Time_12_00_08AM__453__Second_Chance_Exception_C0000008.dmp the assembly instruction at ntdll!KiRaiseUserExceptionDispatcher+37 in C:\WINDOWS\system32\ntdll.dll from Microsoft Corporation has caused an unknown exception (0xc0000008) on thread 0


This exception originated from php_apc!apc_fcntl_unlock+6cb.

This exception occured as a result of an invalid handle passed to KERNEL32!CLOSEHANDLE by the following function:

php_apc!apc_fcntl_unlock+6cb

Please follow up with the vendor of this module, The PHP Group, for further assistance with this issue.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-16 08:21 UTC] coff33cat at gmail dot com
I am getting the same crash with Windows 2003 Server R2, 
Apache 2.2.17 (VC9 build from Apache-Lounge) & PHP 5.3.3 
(VC9 build).

The APC version I'm using is 

php_apc-3.1.5-5.3-vc9-x86.zip (2010-11-03 16:52 -0800)

from http://downloads.php.net/pierre/

The following error is written to the PHP error log:

PHP Fatal error:  PHP Shutdown: apc_shm_detach: shmdt 
failed: in Unknown on line 0
 [2010-11-16 08:29 UTC] pierre dot php at gmail dot com
Sounds like I found the problem (the mem protection is buggy, have to disable it, not used anyway), I will upload new builds later today.
 [2010-11-16 08:42 UTC] pierre dot php at gmail dot com
Please try using:

http://www.php.net/~pierre/php_apc-3.1-svn20101116-nomemprotect-vc9-x86.zip
 [2010-11-17 00:03 UTC] Brian dot White at foxfire74 dot com
I can confirm that whatever change was made and uploaded in php_apc-3.1-svn20101116-nomemprotect-vc9-x86.zip resolved the issue.  I have successfully restarted both the main apache process and its only child or just the child without any errors.

Like coff33cat in run the thread-save VC9 build from ApacheLounge; however, I noticed that there appears to be no NTS VC9 version available and was wondering if there was a reason for this.

Also, can you share the Windows configure.js command line that is customarily used to build APC for those of us that would like to be able to build APC for test/debugging purposes?
 [2010-11-17 05:28 UTC] pierre dot php at gmail dot com
--enable-apc=shared, without enabling memprotect or spinlock.

About NTS, right, I will upload them as soon as possible. It does not work with Apache 2.2 SAPI, only FCGI and not so good (from a perf pov).
 [2010-11-17 05:29 UTC] pierre dot php at gmail dot com
Fixed, disabling memprotect for the windows build (recommended on linux too btw).
 [2011-01-09 18:21 UTC] ricardo dot nuno dot rodrigues at hotmail dot com
Hi Pierre,

I just installed ApacheLounge and APC 3.1.6 and it gave the 
same error:

PHP Fatal error:  PHP Shutdown: apc_shm_detach: shmdt 
failed: in Unknown on line 0

This on restart of Apache.

Thanks
Ricardo
 [2011-01-20 11:29 UTC] bb_plus at hotmail dot com
I would be very appreciative if you could post a VC6 version for PHP 5.2. I am not able to use 5.3 and the shutdown error is causing me lots of problems.
 [2011-06-14 23:41 UTC] yoke dot lee at gmail dot com
Hi Pierre,

Can php_apc-3.1-svn20101116-5.3-vc6-x86.zip be used for PHP 
5.2.17 VC6 on Windows?

Or should I use php_apc-3.1-svn20101116-nomemprotect-vc9-
x86.zip ? 

Appreciate your feedback. Thanks.
 [2017-06-29 03:00 UTC] v at anonymous dot hack
This problem still persists in PHP 7.1.6, windows 10 =(
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Nov 29 08:03:14 2021 UTC