Skip to content

Commit

Permalink
Fix data race in executor with enabling the limit mode
Browse files Browse the repository at this point in the history
The root cause is we write the limitModeFuncsRunning(a wait group)
in the new goroutine, so the Go data race detector will think them
have the data race due to reading and writing in different routines.
  • Loading branch information
git-hulk committed May 7, 2023
1 parent c4e641b commit d029ce4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ func (jf *jobFunction) singletonRunner() {
}

func (e *executor) limitModeRunner() {
e.limitModeFuncWg.Add(1)
for {
select {
case <-e.ctx.Done():
Expand Down Expand Up @@ -169,6 +168,7 @@ func (e *executor) run() {
if countRunning < int64(e.limitModeMaxRunningJobs) {
diff := int64(e.limitModeMaxRunningJobs) - countRunning
for i := int64(0); i < diff; i++ {
e.limitModeFuncWg.Add(1)
go e.limitModeRunner()
e.limitModeFuncsRunning.Add(1)
}
Expand Down

0 comments on commit d029ce4

Please sign in to comment.