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 {