diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-10-10 14:14:55 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-10-10 16:07:53 +0200 |
commit | bc70f2bf123d94fc3226754ec9f1f44748e98162 (patch) | |
tree | b79c329650881a50d5a2b8149574115e6f513ea0 /helpers/general.go | |
parent | 0d7b05be4cb2391cbd280f6109c01ec2d3d7e0c6 (diff) |
helpers: Fix data race in global logger init
Fixes #6409
Diffstat (limited to 'helpers/general.go')
-rw-r--r-- | helpers/general.go | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/helpers/general.go b/helpers/general.go index 5eabda3c6..80c0591b2 100644 --- a/helpers/general.go +++ b/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. |