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?
This is part of a class that is initialized during OnMissionLoaded.Code:double recursInterval = 0.2; public void saveAircraftParams_recurs() { mission.Timeout(recursInterval, () => saveAircraftParams_recurs() ); //Do some work }
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!
Bookmarks