ID:               35612
 Updated by:       [EMAIL PROTECTED]
 Reported By:      alacn dot uhahaa at gmail dot com
-Status:           Open
+Status:           Assigned
 Bug Type:         IIS related
 Operating System: Windows Server 2003
 PHP Version:      5CVS-2005-12-20 (snap)
 Assigned To:      dmitry


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

[2005-12-21 19:08:29] alacn dot uhahaa at gmail dot com

ok, 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);
 }

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

[2005-12-21 11:09:24] [EMAIL PROTECTED]

alacn, could you please explain why WaitForSingleObject() may not work
on thread handle? (it works fine for me).
Is it IIS6 specific behavior?

Also I didn't understand, why you need 30 sec timeout?
The tmeout thread is event based and it never locks. It should quit
right after it gets WM_QUIT.


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

[2005-12-21 08:11:27] vaguener at hotmail dot com

thats right,

when i set the wait time to INFINITE in the current code
"WaitForSingleObject(timeout_thread_handle, INFINITE);"
it never close the worker process.

but on alacn's code it do.
"WaitForSingleObject(timeout_thread_finish, INFINITE);"

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

[2005-12-20 12:38:23] alacn dot uhahaa at gmail dot com

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);
 }
 
 #endif

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

[2005-12-19 08:51:01] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php5.1-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.1-win32-latest.zip

And this time, really make sure you have the right PHP installed. Only
way to be sure is to delete ALL old dlls related to PHP. Especially
from C:\windows\ directory.
Also, make any patches against the latest CVS sources. PHP 4 is too
old.

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

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/35612

-- 
Edit this bug report at http://bugs.php.net/?id=35612&edit=1

Reply via email to