Skip to content

Commit

Permalink
fix: close mysql statement and rows resources when sql exec end (#1720)
Browse files Browse the repository at this point in the history
* fix: close mysql statement and rows resources when sql exec end

* fix: close mysql statement and rows resources when sql exec end

* style: move code to other place

* style: correct the typo(Prepare)

Co-authored-by: 陈文军 <chenwenjun01@corp.netease.com>
  • Loading branch information
chenwenjun-github and chenwenjun01 authored Nov 2, 2021
1 parent f802295 commit bfe4527
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/db/v1beta1/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,12 @@ func (d *dbConn) RegisterObservationLog(trialName string, observationLog *v1beta
// Prepare the statement
stmt, err := d.db.Prepare(sqlQuery)
if err != nil {
return fmt.Errorf("Pepare SQL statement failed: %v", err)
return fmt.Errorf("Prepare SQL statement failed: %v", err)
}

// Close the statement
defer stmt.Close()

// Execute INSERT
_, err = stmt.Exec(values...)
if err != nil {
Expand Down Expand Up @@ -176,6 +179,8 @@ func (d *dbConn) GetObservationLog(trialName string, metricName string, startTim
if err != nil {
return nil, fmt.Errorf("Failed to get ObservationLogs %v", err)
}
// Close the rows
defer rows.Close()
result := &v1beta1.ObservationLog{
MetricLogs: []*v1beta1.MetricLog{},
}
Expand Down

0 comments on commit bfe4527

Please sign in to comment.