From 471bc39c936de204c629c67e235d739a0f61defa Mon Sep 17 00:00:00 2001 From: John Roesler Date: Thu, 20 Oct 2022 11:28:27 -0500 Subject: [PATCH] if job chains are used improperly we can end up with jobs with nil functions (#388) * if job chains are used improperly we can end up with jobs with nil functions * Update executor.go * Update executor.go --- executor.go | 4 ++-- scheduler.go | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/executor.go b/executor.go index 9a9cd220..5d82d2cd 100644 --- a/executor.go +++ b/executor.go @@ -47,6 +47,8 @@ func (e *executor) start() { case f := <-e.jobFunctions: runningJobsWg.Add(1) go func() { + defer runningJobsWg.Done() + panicHandlerMutex.RLock() defer panicHandlerMutex.RUnlock() @@ -58,8 +60,6 @@ func (e *executor) start() { }() } - defer runningJobsWg.Done() - if e.maxRunningJobs != nil { if !e.maxRunningJobs.TryAcquire(1) { diff --git a/scheduler.go b/scheduler.go index 9a8c0965..69f03103 100644 --- a/scheduler.go +++ b/scheduler.go @@ -545,6 +545,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 {