Skip to content

Commit

Permalink
METAL-2763 fix mysql connection leak (#69)
Browse files Browse the repository at this point in the history
* METAL-2763 fix mysql connection leak

* METAL-2763 rows.close() only if query has no error
  • Loading branch information
dabde authored Jun 25, 2021
1 parent d7aa317 commit 32b70bf
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions pkg/utils/database/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func (m Mysql) CheckStatus() error {
if err != nil {
return err
}
defer db.Close()

if err := db.Ping(); err != nil {
db.Close()
Expand Down Expand Up @@ -115,12 +114,12 @@ func (m Mysql) executeQuery(query string, admin AdminCredentials) error {
logrus.Fatalf("failed to get db connection: %s", err)
}

defer db.Close()
_, err = db.Query(query)
rows, err := db.Query(query)
if err != nil {
logrus.Debugf("failed to execute query: %s", err)
return err
}
rows.Close()

return nil
}
Expand Down Expand Up @@ -199,7 +198,6 @@ func (m Mysql) isRowExist(query string, admin AdminCredentials) bool {
if err != nil {
logrus.Fatalf("failed to get db connection: %s", err)
}
defer db.Close()

var result string
err = db.QueryRow(query).Scan(&result)
Expand Down

0 comments on commit 32b70bf

Please sign in to comment.