Data race on color.NoColor when commands run concurrently

Aperta
#1,027 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@dandavison ci sta già lavorando.

Dal 11/6/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

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.

Lingua principale
Go
Stelle
390
Fork
123
Merge medio
2g 9h
PR unite (30g)
13

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di temporalio/cli

Tutte le issue di temporalio/cli

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.