You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bugs@httpd.apache.org by bu...@apache.org on 2006/01/27 01:20:36 UTC

DO NOT REPLY [Bug 38410] New: - apr/win32 misinterpreted the meaning of WAIT_ABANDONED

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=38410>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=38410

           Summary: apr/win32 misinterpreted the meaning of WAIT_ABANDONED
           Product: APR
           Version: 1.2.2
          Platform: PC
        OS/Version: Windows 2000
            Status: NEW
          Severity: normal
          Priority: P2
         Component: APR
        AssignedTo: bugs@httpd.apache.org
        ReportedBy: kiyolee@hotmail.com


APR interpret WAIT_ABANDONED as equivalent to WAIT_OBJECT_0 and this is not
correct. See apr_proc_mutex_lock() and apr_proc_mutex_trylock().
According to doco from MS, WAIT_ABANDONED only means the ownership of the mutex
has been changed. The mutex is remain **non-signaled** (or becomes so if it was
signaled), i.e. while one thread get the return code WAIT_ABANDONED, it is
possible that another thread would get the mutex signaled instead. So we can't
simple return APR_SUCCESS as described in this notes in the CHANGES file:

  *) Win32: apr_proc_mutex_trylock and apr_proc_mutex_lock were
     incorrectly returning APR_BUSY if the lock was previously
     held by a thread that exited before releasing the lock
     (ie, if the process holding the lock segfaults). The MSDN
     doc says when WaitForSingleObject returns WAIT_ABANDONED,
     the calling thread takes ownership of the mutex, so these
     two routines should return APR_SUCCESS in this case, not
     APR_BUSY. [Bill Stoddard]

However, we shouldn't return APR_BUSY either.

The normal proper way to handle WAIT_ABANDONED is to put the
WaitForSingleObject() (or any other equivalent API) in a loop, e.g.:

    do {
        rc = WaitForSingleObject(mutex, INFINITE);
    } while (rc == WAIT_ABANDONED);

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org


DO NOT REPLY [Bug 38410] - apr/win32 misinterpreted the meaning of WAIT_ABANDONED

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=38410>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=38410


wrowe@apache.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|bugs@httpd.apache.org       |bugs@apr.apache.org




------- Additional Comments From wrowe@apache.org  2006-09-19 19:54 -------
Mass reassign the 44 open apr-bugs to apr bug list

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org


DO NOT REPLY [Bug 38410] - apr/win32 misinterpreted the meaning of WAIT_ABANDONED

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=38410>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=38410





------- Additional Comments From wrowe@apache.org  2006-02-11 22:42 -------
KB 105678 points out;


  Deadlock. The Synchronization overview says the following about mutexes: 
  If a thread terminates without releasing its ownership of a mutex object, the 
  mutex is considered to be abandoned. A waiting thread can acquire ownership of 
  an abandoned mutex, but the wait function's return value indicates that the 
  mutex is abandoned. 

  WaitForSingleObject() will return WAIT_ABANDONED for a mutex that has been 
  abandoned. However, the resource that the mutex is protecting is left in an 
  unknown state. 

  There is no way to tell whether a critical section has been abandoned.

So for the mutex case, it appears we cannot trust the mutex at this point?

Please provide citations for more recent commentary from Microsoft.  Thanks

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org


DO NOT REPLY [Bug 38410] - apr/win32 misinterpreted the meaning of WAIT_ABANDONED

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=38410>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=38410





------- Additional Comments From kiyolee@hotmail.com  2006-02-01 14:05 -------
I am sure that's not the case.
Normally WaitForSingleObject() will return WAIT_OBJECT_0 and get out of the loop.
Only when the current owner got terminated (usually abnormally like crashing),
then it will return WAIT_ABANDONED and try again.
It is very unlikely all other potential owners got terminated so abnormally all
at the same time. Even when that happens, the current loop would become the
owner and no way it will get WAIT_ABANDONED and definitely it will break out of
the loop.
In other words, the loop will loop only for at maximum the number of processes
using the mutex minus 1.
Reminded WAIT_ABANDONED is an abnormal case and should rarely happen and the
loop is mainly to handle that properly. Anyway, the current implementation is
definitely wrong (returning APR_SUCCESS when the mutex is not actually
signalled) when that happens.
If APR_EAGAIN means that the user needs to call mutex_lock() again to really
acquire the mutex, then that is logically correct.
However, I would rather like to have the lower level code handle the abnormal
case. The application code calling mutex_lock() would be much simplier to worry
about only 2 return codes (APR_SUCCESS or APR_BUSY) instead of 3 (plus
APR_EAGAIN). Also consider everywhere calling mutex_lock() would then need to
have a loop handling APR_EAGAIN as the error code just can't be ignored.

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org


DO NOT REPLY [Bug 38410] - apr/win32 misinterpreted the meaning of WAIT_ABANDONED

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=38410>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=38410





------- Additional Comments From wrowe@apache.org  2006-02-11 22:50 -------
Ok, here's how I read this from WaitForXxx documentation;

  WAIT_ABANDONED
  The specified object is a mutex object that was not released by the thread that 
  owned the mutex object before the owning thread terminated. Ownership of the 
  mutex object is granted to the calling thread, and the mutex is set to 
  nonsignaled. 

So, threads A, B, and C exist.  Thread A created the mutex, while B and C are 
waiting on the mutex.  Thread A exits, thread B is notified WAIT_ABANDONED and
literally now owns the non-signaled mutex.  Thread C must therefore immediately
acquire the mutex (as it is waiting and MS can't be granting ownership to mult
threads, obviously), so thread B should loop and wait again.

Sure sounds like a potential starvation situation if creating threads frequently
terminate, but let's presume sane authors don't kick around mutexes that way :)

I'll apply the patch after reviewing all the places it must go.


-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org


DO NOT REPLY [Bug 38410] - apr/win32 misinterpreted the meaning of WAIT_ABANDONED

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=38410>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=38410





------- Additional Comments From wrowe@apache.org  2006-01-27 21:45 -------
Just tagging this bug for my own followup.

Thank you for your comments; I need to research that this isn't a duplicate
issue.

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org


DO NOT REPLY [Bug 38410] - apr/win32 misinterpreted the meaning of WAIT_ABANDONED

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=38410>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=38410





------- Additional Comments From wrowe@apache.org  2006-01-30 06:34 -------
Your proposed code;

    do {
        rc = WaitForSingleObject(mutex, INFINITE);
    } while (rc == WAIT_ABANDONED);

looks like an infinte loop waiting to happen.

Would returing APR_EAGAIN on WAIT_ABANDONED map appropriately to the condition?

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org


DO NOT REPLY [Bug 38410] - apr/win32 misinterpreted the meaning of WAIT_ABANDONED

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=38410>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=38410





------- Additional Comments From wrowe@apache.org  2006-04-06 11:55 -------
FYI Applied to apr_file_read/write, still many more spots this logic should go.

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org


DO NOT REPLY [Bug 38410] - apr/win32 misinterpreted the meaning of WAIT_ABANDONED

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=38410>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=38410





------- Additional Comments From kiyolee@hotmail.com  2006-02-01 14:20 -------
Forget to mention, even the timeout is INFINITE, WaitForSingleObject() will
return whenever the current owner of the mutex gets terminated.

Also notice that the loop to handle APR_EAGAIN may actually be redundant for
non-win32 platforms which never return anything like WAIT_ABANDONED. So the
tighter loop inside the win32 specific code implies much less overhead to the
mutex api.

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org