Skip to content
Permalink
Browse files

helpers: Fix data race in global logger init

Fixes #6409
  • Loading branch information...
bep committed Oct 10, 2019
1 parent 0d7b05b commit bc70f2bf123d94fc3226754ec9f1f44748e98162
Showing with 11 additions and 4 deletions.
  1. +11 −4 helpers/general.go
@@ -283,6 +283,13 @@ type DistinctLogger struct {
m map[string]bool
}

func (l *DistinctLogger) Reset() {
l.Lock()
defer l.Unlock()

l.m = make(map[string]bool)
}

// Println will log the string returned from fmt.Sprintln given the arguments,
// but not if it has been logged before.
func (l *DistinctLogger) Println(v ...interface{}) {
@@ -347,11 +354,11 @@ var (
DistinctFeedbackLog = NewDistinctFeedbackLogger()
)

// InitLoggers sets up the global distinct loggers.
// InitLoggers resets the global distinct loggers.
func InitLoggers() {
DistinctErrorLog = NewDistinctErrorLogger()
DistinctWarnLog = NewDistinctWarnLogger()
DistinctFeedbackLog = NewDistinctFeedbackLogger()
DistinctErrorLog.Reset()
DistinctWarnLog.Reset()
DistinctFeedbackLog.Reset()
}

// Deprecated informs about a deprecation, but only once for a given set of arguments' values.

0 comments on commit bc70f2b

Please sign in to comment.
You can’t perform that action at this time.