Skip to content

Commit

Permalink
Merge pull request #17629 from tschottdorf/crash-singleton
Browse files Browse the repository at this point in the history
log: don't crash on nil ReportingSettings
  • Loading branch information
tbg authored Aug 14, 2017
2 parents cc645f3 + 5f48f66 commit d7c1ab7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
8 changes: 0 additions & 8 deletions pkg/migration/sqlmigrations/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,13 @@ import (
"github.com/cockroachdb/cockroach/pkg/security"
"github.com/cockroachdb/cockroach/pkg/security/securitytest"
"github.com/cockroachdb/cockroach/pkg/server"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
"github.com/cockroachdb/cockroach/pkg/util/log"
)

func TestMain(m *testing.M) {
security.SetAssetLoader(securitytest.EmbeddedAssets)
serverutils.InitTestServerFactory(server.TestServerFactory)

// TestLeaseExpiration needs log.ReportingSettingsSingleton populated as it
// calls log.Fatal.
st := cluster.MakeClusterSettings()
f := log.ReportingSettings(st.ReportingSettings)
log.ReportingSettingsSingleton.Store(&f)

os.Exit(m.Run())
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/util/log/structured.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ func addStructured(ctx context.Context, s Severity, depth int, format string, ar

// We load the ReportingSettings from the a global singleton in this
// call path. See the singleton's comment for a rationale.
reportingSettings := (ReportingSettingsSingleton.Load()).(*ReportingSettings)
sendCrashReport(ctx, *reportingSettings, reportable, depth+1)
if reportingSettings, ok := (ReportingSettingsSingleton.Load()).(*ReportingSettings); ok {
sendCrashReport(ctx, *reportingSettings, reportable, depth+1)
}
}
// MakeMessage already added the tags when forming msg, we don't want
// eventInternal to prepend them again.
Expand Down

0 comments on commit d7c1ab7

Please sign in to comment.