Skip to content
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

if job chains are used improperly we can end up with jobs with nil functions #388

Merged
merged 4 commits into from Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions executor.go
Expand Up @@ -2,6 +2,7 @@ package gocron

import (
"context"
"log"
JohnRoesler marked this conversation as resolved.
Show resolved Hide resolved
"sync"

"golang.org/x/sync/semaphore"
Expand Down Expand Up @@ -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()

Expand All @@ -58,8 +61,6 @@ func (e *executor) start() {
}()
}

defer runningJobsWg.Done()

if e.maxRunningJobs != nil {
if !e.maxRunningJobs.TryAcquire(1) {

Expand Down
7 changes: 7 additions & 0 deletions scheduler.go
Expand Up @@ -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 {
Expand Down