From 4b29a3d747f354d3ab81f62674964b4678d37b5b Mon Sep 17 00:00:00 2001 From: John Roesler Date: Thu, 20 Oct 2022 11:21:44 -0500 Subject: [PATCH 1/3] if job chains are used improperly we can end up with jobs with nil functions --- executor.go | 6 ++++-- scheduler.go | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/executor.go b/executor.go index e9aafd57..886d8d98 100644 --- a/executor.go +++ b/executor.go @@ -2,6 +2,7 @@ package gocron import ( "context" + "log" "sync" "golang.org/x/sync/semaphore" @@ -47,6 +48,8 @@ func (e *executor) start() { case f := <-e.jobFunctions: runningJobsWg.Add(1) go func() { + defer runningJobsWg.Done() + panicHandlerMutex.RLock() defer panicHandlerMutex.RUnlock() @@ -58,8 +61,6 @@ func (e *executor) start() { }() } - defer runningJobsWg.Done() - if e.maxRunningJobs != nil { if !e.maxRunningJobs.TryAcquire(1) { @@ -106,6 +107,7 @@ func (e *executor) start() { return nil, nil default: } + log.Printf("executor jobFunction: %+v\n", f) runJob() return nil, nil }) diff --git a/scheduler.go b/scheduler.go index 6c249c74..f7a86d9c 100644 --- a/scheduler.go +++ b/scheduler.go @@ -539,6 +539,13 @@ func (s *Scheduler) run(job *Job) { } job.mu.Lock() + + if job.function == nil { + job.mu.Unlock() + s.Remove(job) + return + } + defer job.mu.Unlock() if job.runWithDetails { From aaa45a9c2b452e6c49547764ede7eb1ddac14c72 Mon Sep 17 00:00:00 2001 From: John Roesler Date: Thu, 20 Oct 2022 11:24:00 -0500 Subject: [PATCH 2/3] Update executor.go --- executor.go | 1 - 1 file changed, 1 deletion(-) diff --git a/executor.go b/executor.go index 886d8d98..cded2212 100644 --- a/executor.go +++ b/executor.go @@ -107,7 +107,6 @@ func (e *executor) start() { return nil, nil default: } - log.Printf("executor jobFunction: %+v\n", f) runJob() return nil, nil }) From d3b1299c0dcfb83158cb997eedd789315f87ac5e Mon Sep 17 00:00:00 2001 From: John Roesler Date: Thu, 20 Oct 2022 11:24:14 -0500 Subject: [PATCH 3/3] Update executor.go --- executor.go | 1 - 1 file changed, 1 deletion(-) diff --git a/executor.go b/executor.go index cded2212..642095b1 100644 --- a/executor.go +++ b/executor.go @@ -2,7 +2,6 @@ package gocron import ( "context" - "log" "sync" "golang.org/x/sync/semaphore"