Skip to content

Commit a1a97f8

Browse files
committed
pkg/ccl/oidcccl,pkg/cli,pkg/sql/vecindex/cspann,pkg/storage: bug fixes
The PR fixes several latent bugs identified by using a hybrid linter strategy, detailed in [1]. These comprise, * nil-pointer dereference when err != nil * calling require.* inside background goroutine Epic: none Release note: None [1] https://gist.github.com/srosenberg/3e36c70b5e78c85b84e355ee709b105d
1 parent f5c0bbd commit a1a97f8

File tree

9 files changed

+28
-20
lines changed

9 files changed

+28
-20
lines changed

pkg/ccl/oidcccl/authentication_oidc.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -804,9 +804,9 @@ var ConfigureOIDC = func(
804804
}
805805
} else {
806806
log.Infof(ctx, "OIDC: no identity map found for issuer %s; using %s without mapping", token.Issuer, tokenPrincipal)
807-
if username, err := secuser.MakeSQLUsernameFromUserInput(tokenPrincipal, secuser.PurposeValidation); err != nil {
808-
acceptedUsernames = append(acceptedUsernames, username.Normalized())
809-
}
807+
// N.B. err is elided when using secuser.PurposeValidation.
808+
username, _ := secuser.MakeSQLUsernameFromUserInput(tokenPrincipal, secuser.PurposeValidation)
809+
acceptedUsernames = append(acceptedUsernames, username.Normalized())
810810
}
811811
}
812812
}
@@ -835,6 +835,7 @@ var ConfigureOIDC = func(
835835
if err != nil {
836836
log.Error(ctx, "OIDC: failed to marshal connection parameters (can this happen?)")
837837
http.Error(w, genericCallbackHTTPError, http.StatusInternalServerError)
838+
return
838839
}
839840

840841
w.Header().Add("Content-Security-Policy", "sandbox")

pkg/cli/statement_bundle.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ func getExplainCombinations(
432432
bucketMap[key] = []string{upperBound}
433433
datum, err := rowenc.ParseDatumStringAs(ctx, colType, upperBound, &evalCtx, nil /* semaCtx */)
434434
if err != nil {
435-
panic("failed parsing datum string as " + datum.String() + " " + err.Error())
435+
panic("failed parsing datum string as " + colType.String() + " " + err.Error())
436436
}
437437
if maxUpperBound == nil {
438438
maxUpperBound = datum

pkg/cmd/roachtest/cluster.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2557,6 +2557,9 @@ func (c *clusterImpl) RunWithDetailsSingleNode(
25572557
return install.RunResultDetails{}, errors.Newf("RunWithDetailsSingleNode received %d nodes. Use RunWithDetails if you need to run on multiple nodes.", len(nodes))
25582558
}
25592559
results, err := c.RunWithDetails(ctx, testLogger, options, args...)
2560+
if err != nil {
2561+
return install.RunResultDetails{}, err
2562+
}
25602563
return results[0], errors.CombineErrors(err, results[0].Err)
25612564
}
25622565

pkg/cmd/roachtest/tests/mixed_version_cdc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ func runCDCMixedVersionCheckpointing(ctx context.Context, t test.Test, c cluster
702702
return false
703703
}
704704

705-
if isAffectedBy148620(plan) && isExpectedErrorDueTo148620(err) {
705+
if plan != nil && isAffectedBy148620(plan) && isExpectedErrorDueTo148620(err) {
706706
t.Skipf("expected error due to #148620: %s", err)
707707
}
708708

pkg/cmd/roachtest/tests/tpc_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func loadTPCHDataset(
3838
disableMergeQueue bool,
3939
) (retErr error) {
4040
_, err := db.Exec("SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false;")
41-
if retErr != nil {
41+
if err != nil {
4242
return err
4343
}
4444
defer func() {

pkg/sql/vecindex/cspann/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ go_test(
8888
"@com_github_cockroachdb_datadriven//:datadriven",
8989
"@com_github_cockroachdb_errors//:errors",
9090
"@com_github_guptarohit_asciigraph//:asciigraph",
91+
"@com_github_stretchr_testify//assert",
9192
"@com_github_stretchr_testify//require",
9293
"@org_golang_x_exp//slices",
9394
"@org_gonum_v1_gonum//floats/scalar",

pkg/sql/vecindex/cspann/fixup_processor_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
1515
"github.com/cockroachdb/cockroach/pkg/util/log"
1616
"github.com/cockroachdb/cockroach/pkg/util/stop"
17+
"github.com/stretchr/testify/assert"
1718
"github.com/stretchr/testify/require"
1819
)
1920

@@ -130,16 +131,16 @@ func TestProcess(t *testing.T) {
130131
var counter atomic.Int32
131132
fp.AddSplit(ctx, nil /* treeKey */, 1, 2, false /* singleStep */)
132133
go func() {
133-
require.NoError(t, fp.Process(ctx))
134+
assert.NoError(t, fp.Process(ctx))
134135
// counter should already have been incremented by the foreground
135136
// goroutine.
136-
require.Greater(t, counter.Add(1), int32(1))
137+
assert.Greater(t, counter.Add(1), int32(1))
137138
}()
138139
go func() {
139-
require.NoError(t, fp.Process(ctx))
140+
assert.NoError(t, fp.Process(ctx))
140141
// counter should already have been incremented by the foreground
141142
// goroutine.
142-
require.Greater(t, counter.Add(1), int32(1))
143+
assert.Greater(t, counter.Add(1), int32(1))
143144
}()
144145

145146
// Small delay to allow background goroutines to run.

pkg/sql/vecindex/cspann/index_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"github.com/cockroachdb/cockroach/pkg/util/vector"
3535
"github.com/cockroachdb/datadriven"
3636
"github.com/cockroachdb/errors"
37+
"github.com/stretchr/testify/assert"
3738
"github.com/stretchr/testify/require"
3839
"golang.org/x/exp/slices"
3940
)
@@ -998,7 +999,7 @@ func TestIndexConcurrency(t *testing.T) {
998999
}
9991000

10001001
// Process any remaining fixups and close the index.
1001-
require.NoError(t, index.ProcessFixups(ctx))
1002+
assert.NoError(t, index.ProcessFixups(ctx))
10021003
index.Close()
10031004
}(i, min(i+vecsPerInstance, vectors.Count))
10041005
}

pkg/storage/sst.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -458,20 +458,20 @@ func CheckSSTConflicts(
458458
UpperBound: keys.MaxKey,
459459
})
460460
if err != nil {
461-
rkIter.Close()
462461
return enginepb.MVCCStats{}, err
463462
}
464463
rkIter.SeekGE(NilKey)
465464

466-
if ok, err := rkIter.Valid(); err != nil {
467-
rkIter.Close()
465+
ok, err := rkIter.Valid()
466+
rkIter.Close()
467+
if err != nil {
468468
return enginepb.MVCCStats{}, err
469-
} else if ok {
469+
}
470+
if ok {
470471
// If the incoming SST contains range tombstones, we cannot use prefix
471472
// iteration.
472473
usePrefixSeek = false
473474
}
474-
rkIter.Close()
475475

476476
rkIter, err = reader.NewMVCCIterator(ctx, MVCCKeyIterKind, IterOptions{
477477
UpperBound: rightPeekBound,
@@ -484,16 +484,17 @@ func CheckSSTConflicts(
484484
rkIter.SeekGE(start)
485485

486486
var engineHasRangeKeys bool
487-
if ok, err := rkIter.Valid(); err != nil {
488-
rkIter.Close()
487+
ok, err = rkIter.Valid()
488+
rkIter.Close()
489+
if err != nil {
489490
return enginepb.MVCCStats{}, err
490-
} else if ok {
491+
}
492+
if ok {
491493
// If the engine contains range tombstones in this span, we cannot use prefix
492494
// iteration.
493495
usePrefixSeek = false
494496
engineHasRangeKeys = true
495497
}
496-
rkIter.Close()
497498

498499
if usePrefixSeek {
499500
// Prefix iteration and range key masking don't work together. See the

0 commit comments

Comments
 (0)