Skip to content

Commit 440bb15

Browse files
authored
Fix data race (#209)
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.
1 parent 10cf1fc commit 440bb15

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

logp/core.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"os"
2727
"path/filepath"
2828
"strings"
29+
"sync"
2930
"sync/atomic"
3031
"unsafe"
3132

@@ -66,10 +67,13 @@ type coreLogger struct {
6667
type closerCore struct {
6768
zapcore.Core
6869
io.Closer
70+
mutex sync.Mutex
6971
}
7072

7173
func (c *closerCore) With(fields []zapcore.Field) zapcore.Core {
74+
c.mutex.Lock()
7275
c.Core = c.Core.With(fields)
76+
c.mutex.Unlock()
7377
return c
7478
}
7579

0 commit comments

Comments
 (0)