Skip to content

Commit bfe4527

Browse files
fix: close mysql statement and rows resources when sql exec end (#1720)
* 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: 陈文军 <[email protected]>
1 parent f802295 commit bfe4527

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pkg/db/v1beta1/mysql/mysql.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,12 @@ func (d *dbConn) RegisterObservationLog(trialName string, observationLog *v1beta
129129
// Prepare the statement
130130
stmt, err := d.db.Prepare(sqlQuery)
131131
if err != nil {
132-
return fmt.Errorf("Pepare SQL statement failed: %v", err)
132+
return fmt.Errorf("Prepare SQL statement failed: %v", err)
133133
}
134134

135+
// Close the statement
136+
defer stmt.Close()
137+
135138
// Execute INSERT
136139
_, err = stmt.Exec(values...)
137140
if err != nil {
@@ -176,6 +179,8 @@ func (d *dbConn) GetObservationLog(trialName string, metricName string, startTim
176179
if err != nil {
177180
return nil, fmt.Errorf("Failed to get ObservationLogs %v", err)
178181
}
182+
// Close the rows
183+
defer rows.Close()
179184
result := &v1beta1.ObservationLog{
180185
MetricLogs: []*v1beta1.MetricLog{},
181186
}

0 commit comments

Comments
 (0)