trajectory
go-race-01core-12goDifficulty tier 4/5

Fix a data race in a metrics registry without serialising every read

goconcurrencydata-racelockingrwmutex

Task parameters

Reference steps
9
Step ceiling
40
Runs
15
Solved
14 of 15
Models
5

What is broken, and what fixed means

A latency aggregator shared by every request goroutine and one exporter goroutine fails under the race detector. A mutex was added around the map at some point and the work stopped there: the per endpoint aggregate fields, the histogram behind them and the global Observe counter are all mutated with no lock held, and a cache in front of the map that remembers the most recently used endpoint is read and written unsynchronised on the hot path. The cache is the subtle half. It is also why Reset leaves a stale bucket behind, which is a visible bug rather than a detector warning. The tempting fix is one exclusive mutex around every method, which is race free, correct, and puts every exporter read in a queue behind the others: the hidden suite measures concurrent reads of a deliberately slow read path and rejects it.

Results by model

One group per model. The solve rate carries its spread across seeds, and every run below it links to the full step by step replay.

stub:hasty

66.7%+/- 47.1% over 3 seeds

3 runs, seeds 0, 1, 2

stub:methodical

100.0%+/- 0.0% over 3 seeds

3 runs, seeds 0, 1, 2

stub:reckless

100.0%+/- 0.0% over 3 seeds

3 runs, seeds 0, 1, 2

stub:sloppy

100.0%+/- 0.0% over 3 seeds

3 runs, seeds 0, 1, 2

stub:thrasher

100.0%+/- 0.0% over 3 seeds

3 runs, seeds 0, 1, 2