temporalio / temporalio/cli

Data race on color.NoColor when commands run concurrently

Open
#1,027 0 comments 0 reactions 1 assignee View on GitHub

@dandavison is already working on this.

Since Jun 11, 2026.

Dominant language
Go
Stars
379
Forks
103
Avg merge
2d 11h
Merged PRs (30d)
23

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.