<div dir="ltr">Thanks for the info, Dimiter. That is almost certainly going to bite someone else at some point.</div><br><div class="gmail_quote"><div dir="ltr">On Thu, Jul 16, 2015 at 6:35 AM Dimiter Naydenov <<a href="mailto:dimiter.naydenov@canonical.com">dimiter.naydenov@canonical.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">-----BEGIN PGP SIGNED MESSAGE-----<br>
Hash: SHA1<br>
<br>
Hey all,<br>
<br>
tl;dr; When running $ go test -race -cover with go < 1.3, and you get<br>
data races, try adding "-covermode=atomic" as well to see if they are<br>
caused by the go coverage tool itself. In go 1.3+ -covermode defaults<br>
to atomic, so yet another reason to really move quickly to 1.5 across<br>
the board ASAP.<br>
<br>
I've discovered the hard way the go race detector doesn't play well<br>
with the go coverage tool in golang versions prior to 1.3. With -cover<br>
(and/or -coverprofile=filename, which assumes -cover), the code<br>
instrumentation generated by the coverage tool uses global variables<br>
to track which lines are covered and how many times. This causes the<br>
race detector to report data races in confusing locations (e.g. I had<br>
a whole bunch of them in the provider/ec2 pacakge), which are not<br>
happening without -cover enabled. I've discovered the issue very<br>
easily by adding -test.work argument to "go test". This causes "go<br>
test" to print the temporary work dir used and also keep it after "go<br>
test" completes. Then it's a simple matter of inspecting the work dir<br>
and the actual source files in there, which include race and coverage<br>
instrumentation code added. The DATA RACE output includes paths in<br>
that work dir and line numbers exactly matching the code generated by<br>
- -cover.<br>
<br>
Apparently, adding -covermode=atomic along with -cover and -race,<br>
works around the problem in both golang versions < 1.3 and 1.3+, by<br>
using atomic inc ops rather than global non-goroutine-safe vars.<br>
<br>
An interesting article describing the issue with examples:<br>
<a href="http://herman.asia/running-the-go-race-detector-with-cover" rel="noreferrer" target="_blank">http://herman.asia/running-the-go-race-detector-with-cover</a><br>
<br>
Hopefully this will be helpful to somebody else and save them a few<br>
wasted hours trying to figure out why the result of "go test -race<br>
- -cover" has data races reported, while "go test -race" or "go test<br>
- -cover" for the same tests shows no races at all.<br>
<br>
- --<br>
Dimiter Naydenov <<a href="mailto:dimiter.naydenov@canonical.com" target="_blank">dimiter.naydenov@canonical.com</a>><br>
Juju Core Sapphire team <<a href="http://juju.ubuntu.com" rel="noreferrer" target="_blank">http://juju.ubuntu.com</a>><br>
-----BEGIN PGP SIGNATURE-----<br>
Version: GnuPG v2.0.22 (GNU/Linux)<br>
<br>
iQEcBAEBAgAGBQJVp4kCAAoJENzxV2TbLzHwyJQIALb3MuDz9qSuLwhNNL7DfIjq<br>
DsEV14F82qDbdXcjS42f8I3ZIaq3ii8DQZWyR3dNoTtMOhc4thxIVs6LzHdzUR88<br>
GxFLWZeSgsRzeGj0OVvVGeelwIkqUPORt2Q4m2uziPgVkiczniVwkM9FAC1kdu21<br>
l54ibsIu1TsPwDUQzp6LPSEzP7zhv3pB9h8Qhq4sxoqSUjtQXt6ysgKn88Br/Cjl<br>
7EBkcI0sDkm6bglklztNBh8fQqLUXLHW+cUXhdr/7psnhsAaGXHDEC3u3hPi16X+<br>
Mc0yOrsyOHBNdsTV3J8aWiOI9AJFZWjwEWo1LbUc6vL1znX40LF2Uxq7tTuTJ6g=<br>
=DXZL<br>
-----END PGP SIGNATURE-----<br>
<br>
--<br>
Juju-dev mailing list<br>
<a href="mailto:Juju-dev@lists.ubuntu.com" target="_blank">Juju-dev@lists.ubuntu.com</a><br>
Modify settings or unsubscribe at: <a href="https://lists.ubuntu.com/mailman/listinfo/juju-dev" rel="noreferrer" target="_blank">https://lists.ubuntu.com/mailman/listinfo/juju-dev</a><br>
</blockquote></div>