Bug 8566

Summary: WaitHandle.WaitAny deadlocks if the thread is interrupted
Product: [Mono] Runtime Reporter: Rolf Bjarne Kvinge [MSFT] <rolf>
Component: GeneralAssignee: Rodrigo Kumpera <kumpera>
Severity: normal CC: mhutch, mono-bugs+mono, mono-bugs+runtime, rolf
Priority: ---    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: Proposed fix

Description Rolf Bjarne Kvinge [MSFT] 2012-11-23 07:15:47 UTC
WaitHandle.WaitAny will deadlock if the thread is interrupted.
Comment 1 Rolf Bjarne Kvinge [MSFT] 2012-11-23 07:17:02 UTC
This happens to mdtool:  it calls WaitAny and at process shutdown waits for the thread to finish. The thread has been interrupted, so the WaitAny will never return, thus the process will never exit either.
Comment 2 Rolf Bjarne Kvinge [MSFT] 2012-11-23 07:17:42 UTC
Created attachment 3002 [details]
Proposed fix
Comment 3 Rolf Bjarne Kvinge [MSFT] 2012-11-23 07:19:34 UTC
Rodrigo, I believe this is somewhat your area, can you review the attached patch?
Comment 4 Rolf Bjarne Kvinge [MSFT] 2012-11-23 07:20:32 UTC
It looks like this was detected some time ago: https://bugzilla.novell.com/show_bug.cgi?id=549807#c5
Comment 5 Rodrigo Kumpera 2012-11-23 11:12:19 UTC
The patch looks good except the remaining time calculation doesn't handle ticks overflow.
Comment 6 Rodrigo Kumpera 2012-11-23 11:16:56 UTC
Nerver mind, we're using unsigned math already which handles this fine. So, patch looks good, please commit.
Comment 7 Rolf Bjarne Kvinge [MSFT] 2012-11-23 11:22:41 UTC
Would it be better to use mono_100ns_ticks instead of mono_msec_ticks? If I did the math right it won't overflow in 29k years.
Comment 8 Rodrigo Kumpera 2012-11-23 11:48:09 UTC
It doesn't matter, both are monotonic, which is important. The current schema would only be a problem if we get 2 wrap around in the same call, which is not an issue at all.
Comment 9 Rolf Bjarne Kvinge [MSFT] 2012-11-23 17:16:17 UTC
From the implementation of mono_msec_ticks it looks like it will overflow every 49 days (the number of ms that fit in a uint32).
Comment 10 Rolf Bjarne Kvinge [MSFT] 2012-11-27 19:23:54 UTC
A slightly different version has been committed.

master: 87810b523ab2ce049decbed2184cd005c4f2c20a
2.10: 2209daad1c2fcfdfdd7117c710e01c58e0027d32
Comment 11 Mikayla Hutchinson [MSFT] 2013-05-20 12:56:42 UTC
*** Bug 7003 has been marked as a duplicate of this bug. ***