Bug #77580 [NEW]: DeleteTimerQueueTimer() return code
| From: | oliver dot pfister at contaware dot com | Date: | Thu, 07 Feb 2019 14:21:52 +0000 |
| Subject: | Bug #77580 [NEW]: DeleteTimerQueueTimer() return code | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-219404@lists.php.net to get a copy of this message | ||
From: oliver dot pfister at contaware dot com
Operating system: Windows
PHP version: Irrelevant
Package: Scripting Engine problem
Bug Type: Bug
Bug description:DeleteTimerQueueTimer() return code
Description:
------------
DeleteTimerQueueTimer(HANDLE TimerQueue, HANDLE Timer, HANDLE
CompletionEvent) return code problem in file zend_execute_API.c
Because of vague Microsoft API documentation (see point 3. below) there
is an important implementation difference between Windows and
Wine/ReactOS in case of CompletionEvent set to NULL (PHP uses
DeleteTimerQueueTimer with CompletionEvent set to NULL):
Windows (tested on all versions of Windows from XP to Win10):
calling DeleteTimerQueueTimer returns TRUE if the callback code is not
yet executing, then when the thread (of the pool) enters the callback
code, calling DeleteTimerQueueTimer returns FALSE with ERROR_IO_PENDING.
When the thread (of the pool) has terminated execution of the callback
code, calling DeleteTimerQueueTimer returns again TRUE.
ReactOS/Wine (tested on latest versions of Wine and ReactOS):
calling DeleteTimerQueueTimer always returns FALSE with
ERROR_IO_PENDING.
Important points of the DeleteTimerQueueTimer Microsoft Windows
documentation
(https://msdn.microsoft.com/en-us/library/windows/desktop/ms682569(v=vs.85).aspx):
1. If CompletionEvent is NULL, the function marks the timer for deletion
and returns immediately. If the timer has already expired, the timer
callback function will run to completion.
2. If the error code is ERROR_IO_PENDING, it is not necessary to call
this function again. For any other error, you should retry the call.
3. If there are outstanding callback functions and CompletionEvent is
NULL, the function will fail and set the error code to ERROR_IO_PENDING.
This indicates that there are outstanding callback functions. Those
callbacks either will execute or are in the middle of executing. The
timer is cleaned up when the callback function is finished executing.
As a result in Wine/ReactOS it's not possible to use any PHP, it fails
with a fatal error. In Windows there is the possibility that the timer
is deleted exactly when a thread (of the pool) is executing the
callback, in that case a PHP fatal error would be risen for no good
reason. So I propose to correct the PHP code and always check
GetLastError() making sure it is not returning ERROR_IO_PENDING before
failing.
Test script:
---------------
In zend_set_timeout_ex() and zend_unset_timeout() please correct the
return code check from:
if (!DeleteTimerQueueTimer(NULL, tq_timer, NULL)) {
to:
if (!DeleteTimerQueueTimer(NULL, tq_timer, NULL) && GetLastError() !=
ERROR_IO_PENDING) {
--
Edit bug report at https://bugs.php.net/bug.php?id=77580&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77580&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77580&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77580&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77580&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77580&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77580&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77580&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77580&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77580&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77580&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77580&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77580&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77580&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77580&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77580&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77580&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77580&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77580&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77580&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77580&r=mysqlcfg