Skip to content

Commit

Permalink
apiserver: Close rows before reusing tx (kubeflow#3099)
Browse files Browse the repository at this point in the history
* apiserver: Close rows before reusing tx

Reusing tx before closing rows (might) result in the following error:

[mysql] 2020/02/17 11:55:38 packets.go:427: busy buffer

This closes kubeflow#3098

* Add comment as requested by reviewer
  • Loading branch information
discordianfish authored and Jeffwan committed Dec 9, 2020
1 parent 88ea38a commit 2ffc804
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions backend/src/apiserver/storage/db_status_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ func (s *DBStatusStore) InitializeDBStatusTable() error {
tx.Rollback()
return util.NewInternalServerError(err, "Failed to load database status.")
}
defer rows.Close()
next := rows.Next()
rows.Close() // "rows" shouldn't be used after this point.

// The table is not initialized
if !rows.Next() {
if !next {
sql, args, queryErr := sq.
Insert("db_statuses").
SetMap(defaultDBStatus).
Expand Down
5 changes: 3 additions & 2 deletions backend/src/apiserver/storage/default_experiment_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ func (s *DefaultExperimentStore) initializeDefaultExperimentTable() error {
tx.Rollback()
return util.NewInternalServerError(err, "Failed to get default experiment.")
}
defer rows.Close()
next := rows.Next()
rows.Close()

// If the table is not initialized, then set the default value.
if !rows.Next() {
if !next {
sql, args, queryErr := sq.
Insert("default_experiments").
SetMap(defaultExperimentDBValue).
Expand Down

0 comments on commit 2ffc804

Please sign in to comment.