[Mono-bugs] [Bug 347476] New: Improper measuring of elapsed time in various classes after changing system clock

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Dec 11 04:28:59 EST 2007


https://bugzilla.novell.com/show_bug.cgi?id=347476


           Summary: Improper measuring of elapsed time in various classes
                    after changing system clock
           Product: Mono: Class Libraries
           Version: 1.2.5
          Platform: x86
        OS/Version: Ubuntu
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: CORLIB
        AssignedTo: mono-bugs at ximian.com
        ReportedBy: przemyslaw.gwozdz at gmail.com
         QAContact: mono-bugs at ximian.com
          Found By: Development


This bug is related to thread synchronization events (e.g. ManualResetEvent),
System.Timers.Timer, System.Threading.Timer and possibly to some other classes.
Measuring elapsed time in those classes is damaged when user changes current
system time. This bug doesn't appear under Windows.

Example 1:
- System.Threading.Timer is started with 5 seconds interval
- if user changes system clock one minute to the future then Timer will fire
immediately
- if user changes system clock one minute to the past then Timer will fire
after 65 seconds

Expected results:
Timer should always fire with requested interval, regardless of any system
clock changes.

Code for Example 1:

using System;
using System.Threading;
class Program
{
        static void Main(string[] args)
        {
                Console.WriteLine("Starting timer with 5 seconds interval...");
                new Timer(new TimerCallback(Callback), null, 0, 5000);
                Console.ReadLine();
        }

        static void Callback(Object state)
        {
                Console.WriteLine("Callback executed! Current system time =
{0}", DateTime.Now);
        }
}


Example 2:
- thread enters ManualResetEvent.WaitOne method with timeout 60 seconds
- if user changes system clock one minute to the future then thread will
immediately leave WaitOne
- if user changes system clock one minute to the past then thread will wait in
WaitOne for 60 more seconds than requested

Expected results:
Time spent in WaitOne method should depend only on provided timeout, not on any
changes of system clock.

Code for Example 2:

using System;
using System.Threading;
class Program
{
        static void Main(string[] args)
        {
                Console.WriteLine("Entering WaitOne, timeout 60 seconds, try
changing system time...");
                ManualResetEvent mre = new ManualResetEvent(false);
                mre.WaitOne(60000, false);
                Console.WriteLine("Finished waiting");
        }
}


Remarks:
This bug can appear whenever system clock is changed. For example:
- user changes time manually
- daylight-saving time change occures
- clock synchronization software updates current time

Solution hints:
Some functions responsible for measuring elapsed time are using C-library
function "gettimeofday" which depends on current system time. They should
probably use "clock_gettime" with "CLOCK_MONOTONIC" parameter.
Changes are probably needed in files:
- mono/io-layer/misc.c
- mono/io-layer/mono-mutex.c
- mono/io-layer/timefuncs.c


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list