Skip to content

Commit

Permalink
sql: Fix mutex leak within TestCheckConstraintDropAndColumn
Browse files Browse the repository at this point in the history
The test does not unlock the jobControlMu mutex in the case
of an error. This PR fixes that.

Epic: none
Fixes: #107433
Release note: none
  • Loading branch information
rimadeodhar committed Aug 1, 2023
1 parent 37e61e9 commit e578000
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/sql/schema_changer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6991,6 +6991,8 @@ func TestCheckConstraintDropAndColumn(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)
ctx := context.Background()

// jobControlMu guards changes to the shared delayJobChannels array.
var jobControlMu syncutil.Mutex
var delayJobList []string
var delayJobChannels []chan struct{}
Expand All @@ -7002,10 +7004,14 @@ func TestCheckConstraintDropAndColumn(t *testing.T) {
params.Knobs = base.TestingKnobs{
SQLSchemaChanger: &sql.SchemaChangerTestingKnobs{
RunBeforeResume: func(jobID jobspb.JobID) error {
// We cannot use defer jobControlMu.Unlock within this routine
// as we need to unlock the jobControlMu conditionally prior to waiting on
// `channel` below.
lockHeld := true
jobControlMu.Lock()
scJob, err := s.JobRegistry().(*jobs.Registry).LoadJob(ctx, jobID)
if err != nil {
jobControlMu.Unlock()
return err
}
pl := scJob.Payload()
Expand Down

0 comments on commit e578000

Please sign in to comment.