From 4c518055f46669be1daa064e2f00cfd3d9787387 Mon Sep 17 00:00:00 2001 From: Claudio Costa Date: Tue, 8 Sep 2020 20:36:42 +0200 Subject: [PATCH] [MM-27952] Fix some logging related races (#15404) * Fix some logging races * Move initLogging after config store initialization --- app/server.go | 4 +++- mlog/testing.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/server.go b/app/server.go index cc6baba532..c829dc5885 100644 --- a/app/server.go +++ b/app/server.go @@ -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)) diff --git a/mlog/testing.go b/mlog/testing.go index f66c0f4d45..1f2f437fac 100644 --- a/mlog/testing.go +++ b/mlog/testing.go @@ -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(),