You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
A race exists in the WithLazy implementation. lazyWithCore's own methods are protected from it, but since Core is embedded, methods from Core (in this case, Enabled()) do an unsynchronized read.
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
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: