Bug 8566 - WaitHandle.WaitAny deadlocks if the thread is interrupted
Summary: WaitHandle.WaitAny deadlocks if the thread is interrupted
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Rodrigo Kumpera
URL:
: 7003 ()
Depends on:
Blocks:
 
Reported: 2012-11-23 07:15 UTC by Rolf Bjarne Kvinge [MSFT]
Modified: 2013-05-20 12:56 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Proposed fix (7.10 KB, patch)
2012-11-23 07:17 UTC, Rolf Bjarne Kvinge [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

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. ***