-
-
Notifications
You must be signed in to change notification settings - Fork 314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] - System Time Change Effects Scheduled Jobs #438
Comments
As a comparison, I performed a similar test with the APScheduler library in Python. When the time is changed, I observe that library misses an instance of the job but then resumes work on subsequent ticks:
This would be reasonable behavior for gocron. |
There is an accepted proposal golang/go#36141 for Go to add a concept of |
Is this the same jasonlvhit/gocron#44 ? |
I kind of wonder if more is going on here... I've started experiencing this with duration and cron jobs after upgrading from 1.x -> 2.x and it's happening on Windows, which according to Go's comments should already be using "real time"? |
This is why I'm not 100% sure this is completely related to Golang time issues. I frequently see this in 2.x after a Windows system goes to sleep. In my case I have several 1 minute cron schedules running independently. I added log messages to the top when the schedule gets triggered and at the end of the schedule task to log the next run time. You can see after the system wakes up, one of the cron schedules has it's 'Next Run' time set to a value in the past despite the log timestamps and the timestamp in the log messages themselves reflecting the accurate system time. Last log entry before system sleep (for a different schedule keyed as 'net'):
After system wakeup, the schedule keyed as 'disk' will never run again as its next schedule is in the past:
Note that in the log messages above, the accurate timestamps shown were simply using |
@FramnkRulez Agreed that there is a portion of this issue that can be tackled in gocron v2. I put up a release candidate - if you're able to test and confirm that it resolves this issue with the machine going to sleep and attempting to run a next time in the past, that would be super helpful. v2.1.2-rc-1 |
@JohnRoesler Initial testing seems to show that this RC addresses the problem I was seeing! I'll keep an eye out for anything unusual. |
@FramnkRulez v2.1.2 has this fix in it for the next run time ending up in the past 👍 The other direction (time was ahead of where it should be) of this issue - say time being synced from 11am back to 9am, is an interesting problem. From the scheduler perspective, this would be much more complex to handle 🤔 In my experience working with devices that sync with NTP, I've only ever had to sync time forward (when a device been offline for some time). If you are facing this issue, I'm curious to understand under what circumstances. |
Describe the bug
Scheduled jobs are effected by a system time change. If the next job is scheduled for time X, but the system clock is changed to time X + 1 hour before time X, then the job does not run.
To Reproduce
Steps to reproduce the behavior:
Here is a simple program that will run on Mac OS X that can demonstrate the problem:
Version
v1.19.0
Expected behavior
The expected behavior would be that a job printing "Hello World" would start. After some amount of time the system clock would change (corresponding to when the current time is printed below), but the job would continue running:
The actual behavior is that the job(s) stop shortly after the system clock is changed:
Additional context
The problem was first observed on a device with an inaccurate date & time setting. Jobs were scheduled and started. Later the device obtained the correct date & time from NTP. When that happened the jobs stopped. Looking at the
NextRun()
information on the jobs, one could see they were scheduled to run "in the past." In some cases theNextRun()
was actually before theLastRun()
.The text was updated successfully, but these errors were encountered: