[MM-27952] Fix some logging related races (#15404)

* Fix some logging races

* Move initLogging after config store initialization
This commit is contained in:
Claudio Costa
2020-09-08 20:36:42 +02:00
committed by GitHub
parent 44079785eb
commit 4c518055f4
2 changed files with 4 additions and 2 deletions

View File

@@ -184,7 +184,6 @@ func NewServer(options ...Option) (*Server, error) {
hashSeed: maphash.MakeSeed(),
}
mlog.Info("Server is initializing...")
for _, option := range options {
if err := option(s); err != nil {
return nil, errors.Wrap(err, "failed to apply option")
@@ -204,6 +203,9 @@ func NewServer(options ...Option) (*Server, error) {
mlog.Error(err.Error())
}
// This is called after initLogging() to avoid a race condition.
mlog.Info("Server is initializing...")
// It is important to initialize the hub only after the global logger is set
// to avoid race conditions while logging from inside the hub.
fakeApp := New(ServerConnector(s))

View File

@@ -35,7 +35,7 @@ func NewTestingLogger(tb testing.TB, writer io.Writer) *Logger {
logrLogger: newLogr(),
}
logWriterCore := zapcore.NewCore(makeEncoder(true), logWriterSync, testingLogger.consoleLevel)
logWriterCore := zapcore.NewCore(makeEncoder(true), zapcore.Lock(logWriterSync), testingLogger.consoleLevel)
testingLogger.zap = zap.New(logWriterCore,
zap.AddCaller(),