helpers: Fix data race in global logger init
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 10 Oct 2019 12:14:55 +0000 (14:14 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 10 Oct 2019 14:07:53 +0000 (16:07 +0200)
Fixes #6409

helpers/general.go

index 5eabda3c605ce4c78f8c2f1e91bbc5e11dbc928d..80c0591b29282ef1dfe0212ada98cd2d5df02dc1 100644 (file)
@@ -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.