Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race on global variable: factorials #368

Open
nasermirzaei89 opened this issue May 13, 2024 · 1 comment
Open

Race on global variable: factorials #368

nasermirzaei89 opened this issue May 13, 2024 · 1 comment

Comments

@nasermirzaei89
Copy link

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 (#229), it's not goroutine safe and should have a lock.

@mwoss
Copy link
Member

mwoss commented May 14, 2024

Hi @nasermirzaei89! Thanks for bringing this issue up.
I was aware of this potential race condition problem during the implementation of ExpTaylor, but I though my lock-less approach would be sufficient for - https://github.com/shopspring/decimal/blob/master/decimal.go#L1089:L1099. I guess I was wrong, I would need to take a closer look on that 👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants