From d029ce4af7b37befe9b943fb52ed09ee3d779dfc Mon Sep 17 00:00:00 2001 From: git-hulk <hulk.website@gmail.com> Date: Sun, 7 May 2023 12:03:34 +0800 Subject: [PATCH] Fix data race in executor with enabling the limit mode 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. --- executor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor.go b/executor.go index 3f1b674c..708e7cbc 100644 --- a/executor.go +++ b/executor.go @@ -96,7 +96,6 @@ func (jf *jobFunction) singletonRunner() { } func (e *executor) limitModeRunner() { - e.limitModeFuncWg.Add(1) for { select { case <-e.ctx.Done(): @@ -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) }