Race on global variable: factorials
Author: nasermirzaei89Created May 13, 2024Updated Jan 21, 2025
We get a RACE error on running tests in the production with the flag -race enabled.
And the stack shows it comes from here:
I believe that the reason is multiple goroutines are calling method ExpTaylor and this method manipulates the shared variable factorials (https://github.com/shopspring/decimal/blob/master/decimal.go#L84).
As you used a global variable for caching factorials (https://github.com/shopspring/decimal/pull/229), it's not goroutine safe and should have a lock.
Source: shopspring/decimal