Skip to content

Commit

Permalink
fix: data race for get jobs map (#558)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfyiamcool committed Sep 4, 2023
1 parent b339f73 commit fd26595
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ func (s *Scheduler) Jobs() []*Job {

// JobsMap returns a map of job uuid to job
func (s *Scheduler) JobsMap() map[uuid.UUID]*Job {
return s.jobsMap()
s.jobsMutex.RLock()
defer s.jobsMutex.RUnlock()
jobs := make(map[uuid.UUID]*Job, len(s.jobs))
for id, job := range s.jobs {
jobs[id] = job
}
return jobs
}

func (s *Scheduler) jobsMap() map[uuid.UUID]*Job {
Expand Down

0 comments on commit fd26595

Please sign in to comment.