Results 1 to 6 of 6

Thread: Recursive Timeout stops randomly - help!?

  1. #1
    Ace
    Join Date
    May 2015
    Location
    Kansas City, Missouri area
    Posts
    515
    Post Thanks / Like
    Total Downloaded
    130.02 MB

    Recursive Timeout stops randomly - help!?

    So a very, very common technique we use in our servers is to recursively call a function via Timeout so as to periodically do something throughout the mission.

    We have various timers like that, that run every 5 seconds, 20 seconds, 45 seconds, 2-5-10 minutes, etc.

    But there is one that runs every 0.2 seconds. And--we have recently discovered!--after running maybe 10000, 20000, 30000, or 50000 times it will randomly stop.

    So my questions are:

    • Does anyone know why it stops?
    • Does anyone know how to address the problem?
    • Or, does anyone know a better technique to achieve the same result?

    Code:
            double recursInterval = 0.2;
    
            public void saveAircraftParams_recurs()
            {
    
                    mission.Timeout(recursInterval, () =>  saveAircraftParams_recurs() );
    
                    //Do some work
                        
    
            }
    This is part of a class that is initialized during OnMissionLoaded.

    I don't see any errors happening when it quits. (Though I have found a number of errors that don't display any error message in the log file - so a "silent error" is certainly a possibility. I tried wrapping it in try/catch and printing the error in the catch, but that didn't find any errors, either)

    I've only just started specifically monitoring it and so far it is run for 3 hours and crashed (55000 runs), then 8 minutes and crashed (1500 runs), then about 6 hours with no crash (over 100000 runs), server restart, then 2 hours and crash (31000 runs). So the occurrence is pretty random.

    I'm worried about the other roughly 100 or maybe 1000 times we have used this same technique in the servers, if recursive timeout loops randomly quit working. Something that runs as infrequently as every 30 seconds runs ~1500 times in the course of a 15 hour mission. So that means that recursive timeouts that run every 5-10-15-30-45-60 seconds are in considerable danger of randomly stopping during the course of a normal mission.

    Whereas previously I have considered this technique to be 100% bulletproof.

    Any/all ideas & thoughts welcome!
    System: Microsoft Windows 10 Pro 64 bit, 10.0.18362 N/A Build 18362, 20,437 MB |
    ASUS GeForce GTX 1060 3GB | Intel Core i5-2500 Quad-Core Processor 3.3 GHz 6 MB Cache LGA 1155 | Intel DB65AL motherboard | ARCTIC Freezer i11 CPU Cooler | SVGA 500 watt power supply | Microsoft Sidewinder 2 Force Feedback joystick

  2. #2
    Supporting Member
    Join Date
    Nov 2015
    Location
    Oak Island, NC
    Posts
    790
    Post Thanks / Like
    Total Downloaded
    80.50 MB

    Re: Recursive Timeout stops randomly - help!?

    Is there a way to periodically force the timers to stop and then restart, say, every few minutes? Or test to see if a timer is working, and restart if it is not?
    Windows 10 Pro 64-bit
    AMD Ryzen 7 3700X 8-Core, 16-Thread
    32GB RAM
    NVidia GeForce GTX1080 (Asus Rog Strix GTX 1080)
    1 TB SSD
    LG 4K 55" TV
    Gear-Falcon General Purpose Joystick Controller, Gear-Falcon Quadrant and Trim, Gear-Falcon BF-109 Water Radiator Crank

    "Find out what you don't do well, and then DON'T DO IT!" - Alf

  3. #3
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Recursive Timeout stops randomly - help!?

    Quote Originally Posted by TWC_Flug View Post

    • Or, does anyone know a better technique to achieve the same result?
    I use the System.Stopwatch for this. Make a Stopwatch for each task, you can stop, pause, reset, etc.

  4. #4
    varrattu
    Guest

    Re: Recursive Timeout stops randomly - help!?

    Quote Originally Posted by TWC_Flug View Post
    ...I don't see any errors happening when it quits. (Though I have found a number of errors that don't display any error message in the log file - so a "silent error" is certainly a possibility. I tried wrapping it in try/catch and printing the error in the catch, but that didn't find any errors, either) ...
    Did you consider other possible issues?

    Graphic or audio anomalies, problems with drivers, operating system, settings, third party software might also be possible in case of time-critical processes.

    ~V~

  5. #5
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Recursive Timeout stops randomly - help!?

    Unlimited recursive calls are memory leaks.

    Dicta Oskar: Do not call this recursively.

  6. #6
    Ace
    Join Date
    May 2015
    Location
    Kansas City, Missouri area
    Posts
    515
    Post Thanks / Like
    Total Downloaded
    130.02 MB

    Re: Recursive Timeout stops randomly - help!?

    Quote Originally Posted by ATAG_Oskar View Post
    Unlimited recursive calls are memory leaks.

    Dicta Oskar: Do not call this recursively.
    Thanks to everyone for comments & ideas - very helpful.

    On the previous somewhat similar big project I worked on--in a different language of course--the recursive timeout kind of calls were the only way to get something to happen periodically, and so it was very common practice and we had a set of standard practices about how best to do it, etc.

    So, it's just kind of a natural habit.

    What I came up for this is something like:

    Code:
                timer = new System.Threading.Timer(
                    new TimerCallback(saveAircraftParams_recurs),
                    null,
                    1000, //wait time @ startup, in ms
                    recursInterval); //periodically call the callback at this interval
    Seems to work. If there is a better way, I'm all ears.

    FYI there are two "timer" classes, System.Timers.Timer and System.Threading.Timer. Sort of confusing and I'm not really sure which is preferable.
    System: Microsoft Windows 10 Pro 64 bit, 10.0.18362 N/A Build 18362, 20,437 MB |
    ASUS GeForce GTX 1060 3GB | Intel Core i5-2500 Quad-Core Processor 3.3 GHz 6 MB Cache LGA 1155 | Intel DB65AL motherboard | ARCTIC Freezer i11 CPU Cooler | SVGA 500 watt power supply | Microsoft Sidewinder 2 Force Feedback joystick

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •