Bug 42688

Summary: Can't wait for more than 429496 ms (429s)
Product: [Mono] Runtime Reporter: Rolf Bjarne Kvinge [MSFT] <rolf>
Component: GeneralAssignee: Rodrigo Kumpera <kumpera>
Severity: critical CC: archipl33, Daniel.Regner, kumpera, ludovic, luis.aguilera, mamo, mono-bugs+mono, mono-bugs+runtime, shrutis
Priority: Highest    
Version: 4.4.0 (C7)   
Target Milestone: (C7)   
Hardware: PC   
OS: Mac OS   
Tags: DefectEscapeReview_Done Is this bug a regression?: Yes
Last known good build: 4.2

Description Rolf Bjarne Kvinge [MSFT] 2016-07-20 13:26:56 UTC
Test case:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;

class Program
    static void Main(string[] args)
		var ts = TimeSpan.FromMilliseconds (429497);
		var mre = new ManualResetEvent (false);
		var watch = new Stopwatch ();
		watch.Start ();
		var rv = mre.WaitOne (ts, false);
		watch.Stop ();
		Console.WriteLine ("Tried to wait for {0}s and waited only for {1}s result: {2}", ts.TotalSeconds, watch.Elapsed.TotalSeconds, rv);

Running this exits pretty much instantly with:

$ mono test.exe
Tried to wait for 429.497s and waited only for 0.0001574s result: False

The problem is here https://github.com/mono/mono/blob/f136599a685a26f467bd8f5a1b0c98b6af65c779/mono/io-layer/wait.c#L143:

		end = mono_100ns_ticks () + timeout * 1000 * 10;

when timeout > 429496 the multiplication overflows and wraps around.

I can reproduce both with mono master and current stable:

$ mono --version
Mono JIT compiler version 4.4.1 (mono-4.4.0-branch-c7sr0/4747417 Mon Jun 20 15:43:48 EDT 2016)
Comment 1 Rolf Bjarne Kvinge [MSFT] 2016-07-20 13:28:58 UTC
Raising importance since this is a regression.
Comment 2 Rolf Bjarne Kvinge [MSFT] 2016-07-20 13:30:10 UTC
Ludovic, this seems to have been introduced with https://github.com/mono/mono/commit/55492cbbee242e6fc844863c6360411e77ae3c52.
Comment 3 Rodrigo Kumpera 2016-07-20 17:51:01 UTC
Comment 4 Rodrigo Kumpera 2016-07-21 01:31:41 UTC
Fixed on mono 4.4.0, 4.6.0 and master.

Now pushing PRs to bump the products.
Comment 5 Shruti 2016-07-21 11:11:46 UTC
Reproduce Status:
I am able to reproduce this issue with above stable Mono 4.4.1 (mono-4.4.0-branch-c7sr0/4747417) (64-bit) and got following result:
 Tried to wait for 429.497s and waited only for 0.0009798s result: False

Screencast: http://www.screencast.com/t/6kqcIlLc

Verify Status: C7SR1
I have checked this issue with mono-4.4.0-c7sr1 (revision e4b69ff6df35788d03bacb507af05369bc42ae73) and observed that now its waiting for 429s. Now, I am getting following result
Tried to wait for 429.497s and waited only for 429.4981815s result: False

Screencast: http://www.screencast.com/t/Buz16wHSJ
Environment Info:https://gist.github.com/shrutis360/d18d132d5e9f072fb5509fa24e1c71b9

Verify Status: Master
Working fine with latest master MonoFramework-MDK- and got following result
Tried to wait for 429.497s and waited only for 429.5034533s result: False 

mono-4.4.0-branch: a7de69bbcd02d16f259e88217176931dd81c1853 is not build yet on wrench so not able to verify this issue here.
On above behaviour of C7SR1 and Master, I changing bug status as 'Verified' and will verify the bug on C7 mono-4.4.0-branch once get build successfully.
Comment 6 Ludovic Henry 2016-07-22 22:00:51 UTC
*** Bug 41701 has been marked as a duplicate of this bug. ***
Comment 7 Ludovic Henry 2016-07-22 22:01:17 UTC
*** Bug 42295 has been marked as a duplicate of this bug. ***