瀏覽代碼

Fix: Handle concurrent threads using mutex on the rainbowColor function

Signed-off-by: AhmedGrati <[email protected]>
AhmedGrati 2 年之前
父節點
當前提交
df70735295
共有 1 個文件被更改,包括 4 次插入0 次删除
  1. 4 0
      cmd/formatter/colors.go

+ 4 - 0
cmd/formatter/colors.go

@@ -19,6 +19,7 @@ package formatter
 import (
 	"fmt"
 	"strconv"
+	"sync"
 
 	"github.com/docker/compose/v2/pkg/api"
 )
@@ -88,8 +89,11 @@ func makeColorFunc(code string) colorFunc {
 var nextColor = rainbowColor
 var rainbow []colorFunc
 var currentIndex = 0
+var mutex sync.Mutex
 
 func rainbowColor() colorFunc {
+	mutex.Lock()
+	defer mutex.Unlock()
 	result := rainbow[currentIndex]
 	currentIndex = (currentIndex + 1) % len(rainbow)
 	return result