Skip to content

Commit

Permalink
Only rollback if there was a failure
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmrod committed Oct 9, 2023
1 parent 064823a commit 28d1df8
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions server/datastore/mysql/query_results.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// OverwriteQueryResultRows overwrites the query result rows for a given query and host
// in a single transaction, ensuring that the number of rows for the given query
// does not exceed the maximum allowed
func (ds *Datastore) OverwriteQueryResultRows(ctx context.Context, rows []*fleet.ScheduledQueryResultRow) error {
func (ds *Datastore) OverwriteQueryResultRows(ctx context.Context, rows []*fleet.ScheduledQueryResultRow) (err error) {
if len(rows) == 0 {
return nil
}
Expand All @@ -23,9 +23,11 @@ func (ds *Datastore) OverwriteQueryResultRows(ctx context.Context, rows []*fleet
return ctxerr.Wrap(ctx, err, "starting a transaction")
}
defer func() {
err := tx.Rollback()
if err != nil {
ds.logger.Log("err", err, "msg", "rolling back transaction")
err := tx.Rollback()
if err != nil {
ds.logger.Log("err", err, "msg", "rolling back transaction")
}
}
}()

Expand Down

0 comments on commit 28d1df8

Please sign in to comment.