Skip to content

Commit

Permalink
fix: clear the limitModeQueue chan on stop (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRoesler committed May 8, 2023
1 parent 2156260 commit 51e4a72
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type executor struct {
limitModeFuncsRunning *atomic.Int64 // tracks the count of limited mode funcs running
limitModeFuncWg *sync.WaitGroup // allow the executor to wait for limit mode functions to wrap up
limitModeQueue chan jobFunction // pass job functions to the limit mode workers
limitModeQueueMu *sync.Mutex // for protecting the limitModeQueue
limitModeRunningJobs *atomic.Int64 // tracks the count of running jobs to check against the max
stopped *atomic.Bool // allow workers to drain the buffered limitModeQueue

Expand All @@ -61,7 +62,7 @@ func newExecutor() executor {
limitModeFuncsRunning: &atomic.Int64{},
limitModeFuncWg: &sync.WaitGroup{},
limitModeRunningJobs: &atomic.Int64{},
limitModeQueue: make(chan jobFunction, 1000),
limitModeQueueMu: &sync.Mutex{},
}
return e
}
Expand Down Expand Up @@ -121,6 +122,10 @@ func (e *executor) start() {
e.jobsWg = &sync.WaitGroup{}

e.stopped = &atomic.Bool{}

e.limitModeQueueMu.Lock()
e.limitModeQueue = make(chan jobFunction, 1000)
e.limitModeQueueMu.Unlock()
go e.run()
}

Expand Down Expand Up @@ -232,5 +237,8 @@ func (e *executor) stop() {
}
if e.limitModeMaxRunningJobs > 0 {
e.limitModeFuncWg.Wait()
e.limitModeQueueMu.Lock()
e.limitModeQueue = nil
e.limitModeQueueMu.Unlock()
}
}

0 comments on commit 51e4a72

Please sign in to comment.