Skip to content

Commit

Permalink
Fix data race (#209)
Browse files Browse the repository at this point in the history
There was a possible data race when calling `With` on a `closerCore`. If
`With` was called from different goroutines, a data race could
occur. This commit fixes it.
  • Loading branch information
belimawr authored May 30, 2024
1 parent 10cf1fc commit 440bb15
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions logp/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"os"
"path/filepath"
"strings"
"sync"
"sync/atomic"
"unsafe"

Expand Down Expand Up @@ -66,10 +67,13 @@ type coreLogger struct {
type closerCore struct {
zapcore.Core
io.Closer
mutex sync.Mutex
}

func (c *closerCore) With(fields []zapcore.Field) zapcore.Core {
c.mutex.Lock()
c.Core = c.Core.With(fields)
c.mutex.Unlock()
return c
}

Expand Down

0 comments on commit 440bb15

Please sign in to comment.