Skip to content

Commit 51d7523

Browse files
craig[bot]yuzefovich
andcommitted
Merge #157773
157773: logictest: fix recently introduced race around allowUnsafe r=yuzefovich a=yuzefovich Just use the atomic since we might have concurrent internal queries reading the current value of the testing knob override. Fixes: #157378 Release note: None Co-authored-by: Yahor Yuzefovich <[email protected]>
2 parents d2bb68c + 4ffe906 commit 51d7523

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

pkg/sql/logictest/logic.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"sort"
2828
"strconv"
2929
"strings"
30+
"sync/atomic"
3031
"testing"
3132
"text/tabwriter"
3233
"time"
@@ -1126,7 +1127,7 @@ type logicTest struct {
11261127

11271128
// allowUnsafe is a variable which controls whether the test can access
11281129
// unsafe internals.
1129-
allowUnsafe bool
1130+
allowUnsafe atomic.Bool
11301131
}
11311132

11321133
func (t *logicTest) t() *testing.T {
@@ -1501,7 +1502,10 @@ func (t *logicTest) newCluster(
15011502
DisableOptimizerRuleProbability: *disableOptRuleProbability,
15021503
OptimizerCostPerturbation: *optimizerCostPerturbation,
15031504
ForceProductionValues: serverArgs.ForceProductionValues,
1504-
UnsafeOverride: func() *bool { return &t.allowUnsafe },
1505+
UnsafeOverride: func() *bool {
1506+
v := t.allowUnsafe.Load()
1507+
return &v
1508+
},
15051509
}
15061510
knobs.SQLExecutor = &sql.ExecutorTestingKnobs{
15071511
DeterministicExplain: true,
@@ -4649,8 +4653,8 @@ func RunLogicTest(
46494653
perErrorSummary: make(map[string][]string),
46504654
rng: rng,
46514655
declarativeCorpusCollector: cc,
4652-
allowUnsafe: true,
46534656
}
4657+
lt.allowUnsafe.Store(true)
46544658
if *printErrorSummary {
46554659
defer lt.printErrorSummary()
46564660
}
@@ -4940,8 +4944,8 @@ func (t *logicTest) setSafetyGate(sql string, skip bool) func() {
49404944
return func() {}
49414945
}
49424946

4943-
t.allowUnsafe = false
4947+
t.allowUnsafe.Store(false)
49444948
return func() {
4945-
t.allowUnsafe = true
4949+
t.allowUnsafe.Store(true)
49464950
}
49474951
}

pkg/sql/logictest/parallel_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ func (t *parallelTest) processTestFile(path string, nodeIdx int, db *gosql.DB, c
6767
// Set up a dummy logicTest structure to use that code.
6868
rng, _ := randutil.NewTestRand()
6969
l := &logicTest{
70-
rootT: t.T,
71-
cluster: t.cluster,
72-
nodeIdx: nodeIdx,
73-
db: db,
74-
user: username.RootUser,
75-
verbose: testing.Verbose() || log.V(1),
76-
rng: rng,
77-
allowUnsafe: true,
70+
rootT: t.T,
71+
cluster: t.cluster,
72+
nodeIdx: nodeIdx,
73+
db: db,
74+
user: username.RootUser,
75+
verbose: testing.Verbose() || log.V(1),
76+
rng: rng,
7877
}
78+
l.allowUnsafe.Store(true)
7979
if err := l.processTestFile(path, logictest.TestClusterConfig{}); err != nil {
8080
log.Dev.Errorf(context.Background(), "error processing %s: %s", path, err)
8181
t.Error(err)

0 commit comments

Comments
 (0)