Skip to content

Commit

Permalink
Fix: free s.Cron on proper opportunity to avoid unexpected crash.
Browse files Browse the repository at this point in the history
  • Loading branch information
clarifysky committed Jul 9, 2020
1 parent b8a2cdd commit 57396ee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions dkron/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ func (a *Agent) Stop() error {

if a.config.Server && a.sched.Started {
a.sched.Stop()
a.sched.ClearCron()
}

if err := a.serf.Leave(); err != nil {
Expand Down
11 changes: 10 additions & 1 deletion dkron/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ func (s *Scheduler) Stop() {
log.Debug("scheduler: Stopping scheduler")
s.Cron.Stop()
s.Started = false
s.Cron = nil
// Keep Cron exists and let the jobs which have been scheduled can continue to finish,
// even the node's leadership will be revoked.
// Ignore the running jobs and make s.Cron to nil may cause whole process crashed.
//s.Cron = nil

// expvars
cronInspect.Do(func(kv expvar.KeyValue) {
Expand All @@ -73,9 +76,15 @@ func (s *Scheduler) Stop() {
// Restart the scheduler
func (s *Scheduler) Restart(jobs []*Job, agent *Agent) {
s.Stop()
s.ClearCron()
s.Start(jobs, agent)
}

// Clear cron separately, this can only be called when agent will be stop.
func (s *Scheduler) ClearCron() {
s.Cron = nil
}

// GetEntry returns a scheduler entry from a snapshot in
// the current time, and whether or not the entry was found.
func (s *Scheduler) GetEntry(jobName string) (cron.Entry, bool) {
Expand Down

0 comments on commit 57396ee

Please sign in to comment.