The Data Race That Wasn't a Bug (and the One That Was)

Imagine this: you are testing the performance of some part of your application. Everything is going smoothly, the numbers look good, and as a last check you turn on Go’s race detector. Then, out of nowhere, it prints a warning you didn’t expect:

WARNING: DATA RACE

So you look at it. You look at it again, and again, and you think: “What the…?” The race is between your code and a goroutine you never started, somewhere deep inside net/http. You have no idea how that is possible, or why. Time to dig in.

That is more or less what happened to Vadim Alekseev while running vmagent under the race detector. He tracked the behavior down, reduced it to a small program, and reported it upstream as golang/go#81445. The same behavior also showed up in vmauth. In the end we left one of those races in place on purpose, and fixed the other. To see why, we first need to understand what the race actually is.