|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-12-09 12:29 UTC] alacn dot uhahaa at gmail dot com
Description:
------------
PHP5 and PHP4 on iis6 (windows server 2003) sometimes crash with access violation
Reproduce code:
---------------
(code at zend_execute_API.c)
before iis shutdown or recycle the pool, it will call "zend_shutdown_timeout_thread()", that will post a quit message on "timeout_thread_id" and return
Expected result:
----------------
"zend_shutdown_timeout_thread()" should wait "timeout_thread" finish before return
Actual result:
--------------
sometimes "zend_shutdown_timeout_thread()" return before the "tiumeout_thread" finish, and the iis release the library, than the iis crash at "timeout_thread_proc()" because the library was released.
the fix for PHP5 and PHP4 at "zend_execute_API.c"
"[...]" means hidden code...
#ifdef ZEND_WIN32
#include <process.h>
/* true global */
[...]
// add next line
static HANDLE timeout_thread_finish_event;
#endif
[...]
static unsigned __stdcall timeout_thread_proc(void *pArgs)
{
[...]
DestroyWindow(timeout_window);
UnregisterClass(wc.lpszClassName, NULL);
// add next line
SetEvent(timeout_thread_finish_event);
return 0;
}
void zend_init_timeout_thread()
{
timeout_thread_event = CreateEvent([..]);
// add next line
timeout_thread_finish_event = CreateEvent(0, 0, 0, 0);
[...]
}
void zend_shutdown_timeout_thread()
{
[...]
PostThreadMessage(timeout_thread_id, WM_QUIT, 0, 0);
// add next line
WaitForSingleObject(timeout_thread_finish_event, 30000);
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 04:00:01 2025 UTC |
ok.. here is udiff for latest cvs (php5.1) what is happenning is that since the thread that created the timeout thread have different access levels than the one that will wait it finish, waitforsingleobject on timeout thread handle wont work right, it will always timeout, and access violation will occur expected: it should return before the timeout, that way wont occur access violation the fix: it should wait at least 30 secs, waitforsingleobject will never elapse all the 30 secs, unless in a bad error, - it will always return before the 30 secs, as it should - btw ...cant php4 be fixed too? :( --- php5.1-200512200930_zend_execute_API.c Fri Dec 16 21:30:06 2005 +++ php5.1-200512200930_fixed_zend_execute_API.c Tue Dec 20 08:44:24 2005 @@ -46,7 +46,7 @@ static WNDCLASS wc; static HWND timeout_window; static HANDLE timeout_thread_event; -static HANDLE timeout_thread_handle; +static HANDLE timeout_thread_finish; static DWORD timeout_thread_id; static int timeout_thread_initialized=0; #endif @@ -1282,6 +1282,7 @@ } DestroyWindow(timeout_window); UnregisterClass(wc.lpszClassName, NULL); + SetEvent(timeout_thread_finish); return 0; } @@ -1289,7 +1290,8 @@ void zend_init_timeout_thread() { timeout_thread_event = CreateEvent(NULL, FALSE, FALSE, NULL); - timeout_thread_handle = _beginthreadex(NULL, 0, timeout_thread_proc, NULL, 0, &timeout_thread_id); + timeout_thread_finish = CreateEvent(0, 0, 0, 0); + _beginthreadex(NULL, 0, timeout_thread_proc, NULL, 0, &timeout_thread_id); WaitForSingleObject(timeout_thread_event, INFINITE); } @@ -1302,8 +1304,7 @@ PostThreadMessage(timeout_thread_id, WM_QUIT, 0, 0); /* Wait for thread termination */ - WaitForSingleObject(timeout_thread_handle, 5000); - CloseHandle(timeout_thread_handle); + WaitForSingleObject(timeout_thread_finish, 30000); } #endifok, i have tested it on iis5 (windows xp) and iis6 (windows 2003), both is configured to use the extension php5isapi.dll. we use WaitForSingleObject to wait the thread finish: - it will return WAIT_OBJECT_0 when the thread finish, - or return WAIT_TIMEOUT if the thread didnt finish before the time elapse the thing is, it should result WAIT_OBJECT_0 meaning that the thread was ended fine. lets debug it, set WITH_ALACN_PATCH to 0 to use current code; or set it to 1 to use fixed code "everyone" user need have full access on the "c:\temp\" otherwise it can fail create the file. on the file c:\temp\php_debug.log: -- means its fine WaitForSingleObject: it returned WAIT_OBJECT_0! thread was ended. -- means that we didnt wait the thread finish WaitForSingleObject: it returned WAIT_TIMEOUT! thread may still running!. -- deadlocked after WaitForSingleObject, process killed! WaitForSingleObject: --- php5.1-200512211530_zend_execute_API.c Tue Dec 20 09:30:10 2005 +++ php5.1-200512211530_debug_zend_execute_API.c Wed Dec 21 15:52:46 2005 @@ -1256,6 +1256,26 @@ } +void save_debug_msg(char *sz) +{ + HANDLE h; + int i; + DWORD dwRW; + + h = CreateFile("c:\\temp\\php_debug.log", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); + if(h == INVALID_HANDLE_VALUE) return; + + SetFilePointer(h, 0, 0, 2); + + i = strlen(sz); + WriteFile(h, sz, i, &dwRW, 0); + + CloseHandle(h); +} + +// change this!! +#define WITH_ALACN_PATCH 1 + static unsigned __stdcall timeout_thread_proc(void *pArgs) { @@ -1284,6 +1304,9 @@ } DestroyWindow(timeout_window); UnregisterClass(wc.lpszClassName, NULL); +#if WITH_ALACN_PATCH + SetEvent(timeout_thread_handle); +#endif return 0; } @@ -1291,20 +1314,42 @@ void zend_init_timeout_thread() { timeout_thread_event = CreateEvent(NULL, FALSE, FALSE, NULL); +#if WITH_ALACN_PATCH + timeout_thread_handle = CreateEvent(0, 0, 0, 0); + _beginthreadex(NULL, 0, timeout_thread_proc, NULL, 0, &timeout_thread_id); +#else timeout_thread_handle = _beginthreadex(NULL, 0, timeout_thread_proc, NULL, 0, &timeout_thread_id); +#endif WaitForSingleObject(timeout_thread_event, INFINITE); } void zend_shutdown_timeout_thread() { + DWORD dw; + if (!timeout_thread_initialized) { return; } PostThreadMessage(timeout_thread_id, WM_QUIT, 0, 0); + save_debug_msg("WaitForSingleObject:\r\n"); + /* Wait for thread termination */ - WaitForSingleObject(timeout_thread_handle, 5000); + dw = WaitForSingleObject(timeout_thread_handle, INFINITE); + switch(dw) + { + case WAIT_OBJECT_0: + save_debug_msg("it returned WAIT_OBJECT_0! thread was ended.\r\n"); + break; + case WAIT_TIMEOUT: + save_debug_msg("it returned WAIT_TIMEOUT! thread may still running!.\r\n"); + break; + default: + save_debug_msg("unknow return.\n"); + break; + } + CloseHandle(timeout_thread_handle); }