-
-
Notifications
You must be signed in to change notification settings - Fork 292
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] - Panic when scheduler is about to reschedule a daily job #696
Comments
I have the same problem in 2.2.6.
I wrote a case to reproduce it. func TestScheduler_RemoveJobs(t *testing.T) {
s := newTestScheduler(t)
s.Start()
s.NewJob(
DurationJob(500*time.Millisecond),
NewTask(func() {}),
WithEventListeners(
BeforeJobRuns(
func(jobID uuid.UUID, jobName string) {
s.RemoveByTags("tag1")
},
),
),
WithTags("tag1"),
)
// wait job running
time.Sleep(10 * time.Second)
} |
Hey @mhyllander thanks for reporting. Are you doing any job removal like the example @chih-ming-lin posted? The text does reliably reproduce the issue and I can patch the bug it highlights. I'm just trying to understand if that is the same issue you are having or not? The issue there is that the job is being removed during the job run itself and i had a map lookup that didn't check if the value was present first. |
@JohnRoesler Thanks for looking into this. The timer job does not remove any jobs itself, but I have other jobs that can remove and add timer jobs. Existing timer jobs are removed using RemoveByTags. However, that happens a few hours before the timer job runs, so when the timer job runs, no other jobs are running and no jobs are being removed. |
You can see my code to reschedule timer jobs here. Due to the way jobs are removed asynchronously, I generate a new unique tag for each "generation" of the timer jobs, so that I can remove the old generation and schedule a new generation. Before using these unique tags, I had problems where the new timer jobs would be removed right after they were created. |
@JohnRoesler It happened again yesterday, using 2.2.6:
The interesting thing is that at 20:00, the timer_off job at 23:00 was removed, and a new timer_off job was scheduled at 22:00. The new timer_off job ran as it should at 22:00, but then at 23:00, when the timer_off job that was removed would have run, a panic occurred. It seems that the job that was removed was still scheduled to run. |
Thanks for confirming. I found and fixed that bug. I'll get it released. |
Describe the bug
Two times now a job that runs once daily has caused a panic. When this happens it seems that the job has not been executed. It should update a database and print some logs, but this does not happen. However, the panic occurs on a line that indicates the job has returned from the executor and is about to be rescheduled.
To Reproduce
I don't have a reliable way of reproducing the problem. Most of the time the job runs as expected, but two times a panic has occurred in the gocron code. The panics have occurred two times with 9 days in between, so they happen only sporadically.
Basically, a job is scheduled by this function:
The scheduler is started like this:
Version
2.2.5
I haven't tried the new 2.2.6, but it can take some time to see if there's any improvement.
Expected behavior
No panic.
Additional context
Stack traces:
The text was updated successfully, but these errors were encountered: