Data race on color.NoColor when commands run concurrently

Offen
#1,027 0 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@dandavison arbeitet bereits daran.

Seit 11.6.2026.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Beschreibung

What's wrong

initCommand in internal/temporalcli/commands.go uses the global color.NoColor from github.com/fatih/color as scratch space. It saves the current value into origNoColor (around line 476), the PersistentPreRunE closure overwrites it based on the --color flag and JSON output, and PersistentPostRun puts it back (line 513).

That's fine for the real CLI, where each invocation is its own process. But the tests run commands concurrently in one process, and then those saves, overwrites and restores race against each other. TestServer_StartDev_ConcurrentStarts is the one that hits it.

Repro
go test -run TestServer_StartDev_ConcurrentStarts -race ./internal/temporalcli/
Race trace
WARNING: DATA RACE
Read at 0x000127f6a36d by goroutine 36941:
  github.com/temporalio/cli/internal/temporalcli.(*TemporalCommand).initCommand()
      internal/temporalcli/commands.go:476
  github.com/temporalio/cli/internal/temporalcli.Execute()
      internal/temporalcli/commands.go:373

Previous write at 0x000127f6a36d by goroutine 68:
  github.com/temporalio/cli/internal/temporalcli.(*TemporalCommand).initCommand.func2()
      internal/temporalcli/commands.go:513
Notes

Found this while fixing #581. IDK if there is a quick fix since color.NoColor is a package global in a third-party library and concurrent commands can't each keep their own value. Either the pre-run/post-run color block needs serializing, or the color preference should live on CommandContext instead of the global.

Vorherrschende Sprache
Go
Sterne
390
Forks
123
Ø Merge
2 T. 9 Std.
Gemergte PRs (30 T.)
13

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus temporalio/cli

Alle Issues in temporalio/cli

Ähnliche Issues

Weitere Issues zu Go

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.