-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 using WithLazy #1426
Comments
Thanks for raising this. I agree atomic load and store are one solution, but a more elegant pattern might be to just return a new Core as has been suggested before, and avoid that torn interface assignment |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
A race exists in the WithLazy implementation.
lazyWithCore
's own methods are protected from it, but sinceCore
is embedded, methods fromCore
(in this case,Enabled()
) do an unsynchronized read.zap/zapcore/lazy_with.go
Lines 41 to 43 in fcf8ee5
The trace below is for v1.27.0.
To Reproduce
Create a logger using WithLazy, then use it in multiple goroutines in parallel.
Expected behavior
No race.
Additional context
Personally I would fix by replacing the embedded
Core
with an atomic.Pointer (as gross as these are for holding interfaces).The text was updated successfully, but these errors were encountered: