From 2936a47239cb4825220ac313a4a7b573c14e17e2 Mon Sep 17 00:00:00 2001 From: hulk Date: Sun, 7 May 2023 12:11:51 +0800 Subject: [PATCH] Fix data race in executor with enabling the limit mode (#474) 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) }