From 0e6e79475a45f2383b7ad0f8adfc539f67ad7cf2 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Wed, 1 Jun 2022 01:25:15 +0200 Subject: [PATCH] Ensure mysql rows responses are closed --- .golangci.yml | 2 ++ go/logic/applier.go | 15 +++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 4a487bd97..af04b55a1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -9,4 +9,6 @@ linters: enable: - gosimple - govet + - rowserrcheck + - sqlclosecheck - unused diff --git a/go/logic/applier.go b/go/logic/applier.go index 9bd2ba86a..d6c271288 100644 --- a/go/logic/applier.go +++ b/go/logic/applier.go @@ -382,10 +382,13 @@ func (this *Applier) ReadMigrationMinValues(uniqueKey *sql.UniqueKey) error { if err != nil { return err } + rows, err := this.db.Query(query) if err != nil { return err } + defer rows.Close() + for rows.Next() { this.migrationContext.MigrationRangeMinValues = sql.NewColumnValues(uniqueKey.Len()) if err = rows.Scan(this.migrationContext.MigrationRangeMinValues.ValuesPointers...); err != nil { @@ -394,8 +397,7 @@ func (this *Applier) ReadMigrationMinValues(uniqueKey *sql.UniqueKey) error { } this.migrationContext.Log.Infof("Migration min values: [%s]", this.migrationContext.MigrationRangeMinValues) - err = rows.Err() - return err + return rows.Err() } // ReadMigrationMaxValues returns the maximum values to be iterated on rowcopy @@ -405,10 +407,13 @@ func (this *Applier) ReadMigrationMaxValues(uniqueKey *sql.UniqueKey) error { if err != nil { return err } + rows, err := this.db.Query(query) if err != nil { return err } + defer rows.Close() + for rows.Next() { this.migrationContext.MigrationRangeMaxValues = sql.NewColumnValues(uniqueKey.Len()) if err = rows.Scan(this.migrationContext.MigrationRangeMaxValues.ValuesPointers...); err != nil { @@ -417,8 +422,7 @@ func (this *Applier) ReadMigrationMaxValues(uniqueKey *sql.UniqueKey) error { } this.migrationContext.Log.Infof("Migration max values: [%s]", this.migrationContext.MigrationRangeMaxValues) - err = rows.Err() - return err + return rows.Err() } // ReadMigrationRangeValues reads min/max values that will be used for rowcopy @@ -459,10 +463,13 @@ func (this *Applier) CalculateNextIterationRangeEndValues() (hasFurtherRange boo if err != nil { return hasFurtherRange, err } + rows, err := this.db.Query(query, explodedArgs...) if err != nil { return hasFurtherRange, err } + defer rows.Close() + iterationRangeMaxValues := sql.NewColumnValues(this.migrationContext.UniqueKey.Len()) for rows.Next() { if err = rows.Scan(iterationRangeMaxValues.ValuesPointers...); err != nil {