anz-bank / pkg

Common ANZ Go packages
https://pkg.go.dev/github.com/anz-bank/pkg
Apache License 2.0
1 stars 9 forks source link

health: Fix data race in health readiness access #72

Closed camscale closed 3 years ago

camscale commented 3 years ago

Make the readiness value a uint32 and read/write it with the atomic package functions LoadUint32 and StoreUint32, instead of unprotected access to a boolean.

The health readiness value is read and written from different goroutines mostly. This was explicitly done without locking as the readiness value was a single bit and nothing that needed to be synchronised. That's still bad. At least, it should be an atomic - no data should be read/written concurrently without an atomic or a mutex or more.

Add a test case that fails the race detector if readiness is not properly protected.