rcrowley / go-metrics

Go port of Coda Hale's Metrics library
Other
3.43k stars 493 forks source link

fix race #265

Closed zhanyr closed 4 years ago

zhanyr commented 4 years ago

we got a race like this :

WARNING: DATA RACE Read at 0x00c000249260 by goroutine 16: gmessage-server/vendor/github.com/rcrowley/go-metrics.(StandardRegistry).registered() /home/work/buildspace/2d9632c8a4/.gopath/src/gmessage-server/vendor/github.com/rcrowley/go-metrics/registry.go:222 +0x91 gmessage-server/vendor/github.com/rcrowley/go-metrics.(StandardRegistry).Each() /home/work/buildspace/2d9632c8a4/.gopath/src/gmessage-server/vendor/github.com/rcrowley/go-metrics/registry.go:67 +0x3c ...

Previous write at 0x00c000249260 by goroutine 131: runtime.mapassign_faststr() /usr/local/go/src/runtime/map_faststr.go:190 +0x0 gmessage-server/vendor/github.com/rcrowley/go-metrics.(StandardRegistry).register() /home/work/buildspace/2d9632c8a4/.gopath/src/gmessage-server/vendor/github.com/rcrowley/go-metrics/registry.go:211 +0x113 gmessage-server/vendor/github.com/rcrowley/go-metrics.(StandardRegistry).GetOrRegister() /home/work/buildspace/2d9632c8a4/.gopath/src/gmessage-server/vendor/github.com/rcrowley/go-metrics/registry.go:103 +0x255 gmessage-server/vendor/github.com/rcrowley/go-metrics.GetOrRegisterTimer() /home/work/buildspace/2d9632c8a4/.gopath/src/gmessage-server/vendor/github.com/rcrowley/go-metrics/timer.go:38 +0x77 ...

mihasya commented 4 years ago

Thanks for catching this, @zhanyr and @lechnertech.

Would one of you mind adding a test that exercises this condition? We do run tests with -race as part of the build, so we can prevent further regressions easily if a test is added. Thanks!

zhanyr commented 4 years ago

done.

mihasya commented 4 years ago

Thanks!