Skip to content

Commit 68b4085

Browse files
timvaillancourtdm-2
andcommitted
Ensure mysql rows responses are closed (#1132)
Co-authored-by: dm-2 <[email protected]>
1 parent 9e0808a commit 68b4085

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

.golangci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ linters:
99
enable:
1010
- gosimple
1111
- govet
12+
- rowserrcheck
13+
- sqlclosecheck
1214
- unused

go/logic/applier.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,13 @@ func (this *Applier) ReadMigrationMinValues(uniqueKey *sql.UniqueKey) error {
381381
if err != nil {
382382
return err
383383
}
384+
384385
rows, err := this.db.Query(query)
385386
if err != nil {
386387
return err
387388
}
389+
defer rows.Close()
390+
388391
for rows.Next() {
389392
this.migrationContext.MigrationRangeMinValues = sql.NewColumnValues(uniqueKey.Len())
390393
if err = rows.Scan(this.migrationContext.MigrationRangeMinValues.ValuesPointers...); err != nil {
@@ -393,8 +396,7 @@ func (this *Applier) ReadMigrationMinValues(uniqueKey *sql.UniqueKey) error {
393396
}
394397
this.migrationContext.Log.Infof("Migration min values: [%s]", this.migrationContext.MigrationRangeMinValues)
395398

396-
err = rows.Err()
397-
return err
399+
return rows.Err()
398400
}
399401

400402
// ReadMigrationMaxValues returns the maximum values to be iterated on rowcopy
@@ -404,10 +406,13 @@ func (this *Applier) ReadMigrationMaxValues(uniqueKey *sql.UniqueKey) error {
404406
if err != nil {
405407
return err
406408
}
409+
407410
rows, err := this.db.Query(query)
408411
if err != nil {
409412
return err
410413
}
414+
defer rows.Close()
415+
411416
for rows.Next() {
412417
this.migrationContext.MigrationRangeMaxValues = sql.NewColumnValues(uniqueKey.Len())
413418
if err = rows.Scan(this.migrationContext.MigrationRangeMaxValues.ValuesPointers...); err != nil {
@@ -416,8 +421,7 @@ func (this *Applier) ReadMigrationMaxValues(uniqueKey *sql.UniqueKey) error {
416421
}
417422
this.migrationContext.Log.Infof("Migration max values: [%s]", this.migrationContext.MigrationRangeMaxValues)
418423

419-
err = rows.Err()
420-
return err
424+
return rows.Err()
421425
}
422426

423427
// ReadMigrationRangeValues reads min/max values that will be used for rowcopy.
@@ -478,10 +482,13 @@ func (this *Applier) CalculateNextIterationRangeEndValues() (hasFurtherRange boo
478482
if err != nil {
479483
return hasFurtherRange, err
480484
}
485+
481486
rows, err := this.db.Query(query, explodedArgs...)
482487
if err != nil {
483488
return hasFurtherRange, err
484489
}
490+
defer rows.Close()
491+
485492
iterationRangeMaxValues := sql.NewColumnValues(this.migrationContext.UniqueKey.Len())
486493
for rows.Next() {
487494
if err = rows.Scan(iterationRangeMaxValues.ValuesPointers...); err != nil {

0 commit comments

Comments
 (0)