Fix for race in logrus.
@@ -154,6 +154,12 @@ func NewFromConfig(conf Config) (ret Server, err error) {
ret.enableProfiling = true
}
+ // This is a check to ensure that we don't repeatedly add a hook
+ // to the "global" log instance on repeated calls to `NewFromConfig`
+ // such as those made in testing. By skipping this we avoid a race
+ // condition in logrus discussed here:
+ // https://github.com/sirupsen/logrus/issues/295
+ if _, ok := log.Hooks[logrus.FatalLevel]; !ok {
log.Hooks.Add(sentryHook{
c: ret.sentry,
hostname: ret.Hostname,
@@ -163,6 +169,7 @@ func NewFromConfig(conf Config) (ret Server, err error) {
logrus.PanicLevel,
},
})
+ }
log.WithField("number", conf.NumWorkers).Info("Preparing workers")
// Allocate the slice, we'll fill it with workers later.
