Fix race condition

This commit is contained in:
Till Faelligen 2023-01-23 10:46:53 +01:00
parent f4d6704d95
commit 333f0596dc
No known key found for this signature in database
GPG key ID: ACCDC9606D472758
2 changed files with 4 additions and 0 deletions

View file

@ -24,6 +24,7 @@ import (
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "strings"
"sync"
"github.com/matrix-org/util" "github.com/matrix-org/util"
@ -37,6 +38,7 @@ import (
// this unfortunately results in us adding the same hook multiple times. // this unfortunately results in us adding the same hook multiple times.
// This map ensures we only ever add one level hook. // This map ensures we only ever add one level hook.
var stdLevelLogAdded = make(map[logrus.Level]bool) var stdLevelLogAdded = make(map[logrus.Level]bool)
var levelLogAddedMu = &sync.Mutex{}
type utcFormatter struct { type utcFormatter struct {
logrus.Formatter logrus.Formatter

View file

@ -85,6 +85,8 @@ func checkSyslogHookParams(params map[string]interface{}) {
} }
func setupStdLogHook(level logrus.Level) { func setupStdLogHook(level logrus.Level) {
levelLogAddedMu.Lock()
defer levelLogAddedMu.Unlock()
if stdLevelLogAdded[level] { if stdLevelLogAdded[level] {
return return
} }