From: Bjørn Erik Pedersen Date: Thu, 10 Oct 2019 12:14:55 +0000 (+0200) Subject: helpers: Fix data race in global logger init X-Git-Tag: v0.59.0~20 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=bc70f2bf1;p=brevno-suite%2Fhugo helpers: Fix data race in global logger init Fixes #6409 --- diff --git a/helpers/general.go b/helpers/general.go index 5eabda3c..80c0591b 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.