Skip to content

Commit e578000

Browse files
committed
sql: Fix mutex leak within TestCheckConstraintDropAndColumn
The test does not unlock the jobControlMu mutex in the case of an error. This PR fixes that. Epic: none Fixes: cockroachdb#107433 Release note: none
1 parent 37e61e9 commit e578000

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pkg/sql/schema_changer_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6991,6 +6991,8 @@ func TestCheckConstraintDropAndColumn(t *testing.T) {
69916991
defer leaktest.AfterTest(t)()
69926992
defer log.Scope(t).Close(t)
69936993
ctx := context.Background()
6994+
6995+
// jobControlMu guards changes to the shared delayJobChannels array.
69946996
var jobControlMu syncutil.Mutex
69956997
var delayJobList []string
69966998
var delayJobChannels []chan struct{}
@@ -7002,10 +7004,14 @@ func TestCheckConstraintDropAndColumn(t *testing.T) {
70027004
params.Knobs = base.TestingKnobs{
70037005
SQLSchemaChanger: &sql.SchemaChangerTestingKnobs{
70047006
RunBeforeResume: func(jobID jobspb.JobID) error {
7007+
// We cannot use defer jobControlMu.Unlock within this routine
7008+
// as we need to unlock the jobControlMu conditionally prior to waiting on
7009+
// `channel` below.
70057010
lockHeld := true
70067011
jobControlMu.Lock()
70077012
scJob, err := s.JobRegistry().(*jobs.Registry).LoadJob(ctx, jobID)
70087013
if err != nil {
7014+
jobControlMu.Unlock()
70097015
return err
70107016
}
70117017
pl := scJob.Payload()

0 commit comments

Comments
 (0)