Skip to content

Commit 2f82071

Browse files
committed
sql/stats: prevent deadlocks in a couple of tests when failing
The deferred functions that close the channel (which can block the server) need to be executed _before_ `Stopper.Stop` of that server. Release note: None
1 parent 8cbf680 commit 2f82071

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

pkg/sql/stats/create_stats_job_test.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,6 @@ func testAtMostOneRunningCreateStatsImpl(t *testing.T, errorOnConcurrentCreateSt
234234

235235
var allowRequest chan struct{}
236236
var allowRequestOpen bool
237-
defer func() {
238-
if allowRequestOpen {
239-
close(allowRequest)
240-
}
241-
}()
242237

243238
filter, setTableID := createStatsRequestFilter(&allowRequest)
244239
var params base.TestClusterArgs
@@ -252,6 +247,13 @@ func testAtMostOneRunningCreateStatsImpl(t *testing.T, errorOnConcurrentCreateSt
252247
const nodes = 1
253248
tc := testcluster.StartTestCluster(t, nodes, params)
254249
defer tc.Stopper().Stop(ctx)
250+
251+
defer func() {
252+
if allowRequestOpen {
253+
close(allowRequest)
254+
}
255+
}()
256+
255257
conn := tc.ApplicationLayer(0).SQLConn(t)
256258
sqlDB := sqlutils.MakeSQLRunner(conn)
257259

@@ -385,11 +387,6 @@ func testBackgroundAutoPartialStatsImpl(t *testing.T, errorOnConcurrentCreateSta
385387

386388
var allowRequest chan struct{}
387389
var allowRequestOpen bool
388-
defer func() {
389-
if allowRequestOpen {
390-
close(allowRequest)
391-
}
392-
}()
393390

394391
filter, setTableID := createStatsRequestFilter(&allowRequest)
395392
var params base.TestClusterArgs
@@ -403,6 +400,13 @@ func testBackgroundAutoPartialStatsImpl(t *testing.T, errorOnConcurrentCreateSta
403400
const nodes = 1
404401
tc := testcluster.StartTestCluster(t, nodes, params)
405402
defer tc.Stopper().Stop(ctx)
403+
404+
defer func() {
405+
if allowRequestOpen {
406+
close(allowRequest)
407+
}
408+
}()
409+
406410
conn := tc.ApplicationLayer(0).SQLConn(t)
407411
sqlDB := sqlutils.MakeSQLRunner(conn)
408412

0 commit comments

Comments
 (0)