Skip to content

Commit df70735

Browse files
TessaIOndeloof
authored andcommitted
Fix: Handle concurrent threads using mutex on the rainbowColor function
Signed-off-by: AhmedGrati <[email protected]>
1 parent d8bf175 commit df70735

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

cmd/formatter/colors.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package formatter
1919
import (
2020
"fmt"
2121
"strconv"
22+
"sync"
2223

2324
"github.com/docker/compose/v2/pkg/api"
2425
)
@@ -88,8 +89,11 @@ func makeColorFunc(code string) colorFunc {
8889
var nextColor = rainbowColor
8990
var rainbow []colorFunc
9091
var currentIndex = 0
92+
var mutex sync.Mutex
9193

9294
func rainbowColor() colorFunc {
95+
mutex.Lock()
96+
defer mutex.Unlock()
9397
result := rainbow[currentIndex]
9498
currentIndex = (currentIndex + 1) % len(rainbow)
9599
return result

0 commit comments

Comments
 (0)