Skip to content

Commit

Permalink
apiserver: Close rows before reusing tx
Browse files Browse the repository at this point in the history
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 #3098
  • Loading branch information
discordianfish committed Feb 18, 2020
1 parent d0ef0ae commit a45acb5
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()

// 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 a45acb5

Please sign in to comment.