stability: protect pkg/flag globals from concurrent mutation #4
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
pkg/flag/flag.goexposes mutable package-level variables (Token,Host,Port,Mode,Debug,Insecure, etc.) that are set once at startup but later read concurrently by every tool handler. Tests (e.g.operation/pull/pull_test.go) directly mutateflag.Token, creating data races against any in-flight tool call whengo test -raceis run alongside the HTTP server.Suggested direction
Two options:
sync.RWMutexand exposeGet/Setaccessors. Lowest churn.Configstruct constructed once incmd/cmd.goand passed via context (matches how the per-request token already flows throughpkg/context.TokenContextKey).Either way: run the test suite with
-racein CI to catch regressions.