What this thread does
Do first: run go test -race ./... with concurrent update scenarios before deciding which shared state needs synchronization.
Short answer
As of November 2026, use Go 1.27.4. Use one mutex for a related-state invariant, or an atomic operation for an independently meaningful value. Review related-state invariants (memory model, atomic contract).
Choose / don't choose
- Mutex: choose a read-modify-write involving related fields; don't protect only writers while readers access the same fields unlocked.
- Atomic: choose an isolated counter or deliberately published immutable snapshot; don't replace a multi-field critical section with unrelated atomic stores (atomic).
- Ownership by channel: choose a single updater; don't let another goroutine bypass the owner. These are design choices under the memory model.
Not for: runtime synctest and HTTP timeout errors; see go-setevent-errno-6-synctest-channel-and-http-timeout-errors.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
-race | go test -race ./...; execute suspected paths and realistic instrumented workloads | Current Go docs | detector |
GORACE.log_path | stderr default; retain CI stderr, or select an artifact prefix producing prefix.pid | Current Go docs | detector |
GORACE.exitcode | 66 default; preserve nonzero command status | Current Go docs | detector |
GORACE.halt_on_error | 1 for fail-fast; 0 default collects further findings | Current Go docs | detector |
GORACE.history_size | 1 default; increase if stack history cannot be restored, at memory cost | Current Go docs | detector |
A concrete CI policy is GORACE='log_path=stderr exitcode=66 halt_on_error=1' go test -race ./.... Retain the complete stderr artifact and avoid wrappers that discard the command's nonzero result.
Order of operations
1. For WARNING: DATA RACE, record the read/write or write/write stacks, shared address, and both goroutine creation sites. Extend workload coverage before interpreting silence as evidence; only executed paths are observed (detector). 2. Identify the invariant, then put every related read and update under the same mutex. Keep lock ownership consistent; do not copy a used Mutex (sync). 3. For the same mutex, the nth Unlock synchronizes before a later mth Lock where n < m. Apply that synchronization relation (sync). If updates must follow sequence numbers, encode that ordering in the protocol. 4. Rerun the triggering concurrent scenario and broader instrumented workload; also assert the invariant itself as an application check (memory model).
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
WARNING: DATA RACE | Unsynchronized conflicting accesses | Protect both sides under the chosen ownership/synchronization rule | detector |
failed to restore the stack | Insufficient retained access history | Increase history_size and retain report artifacts | detector |
runtime.racereadrange() at read site | Historical report: race detector mis-identifies runtime.racereadrange() as the read location | Follow caller frames and preserve a minimal reproduction; don't add a random lock around the reported runtime function | corhere report |
Missing
- No workload can prove absence of all races. The historical location-reporting issue is evidence about diagnostics, not permission to ignore a race.
- Application-level update order and invariants must be specified by the owner.
Checked
2026-11-12; Go release, race guide, memory model, sync/atomic references and corhere's dated report read. No Go test commands executed.
Started from a post by @Go project, packaged by the editor. Original post