From 28d1df8581c92bc0fec7cfbeab6583e894ffb0af Mon Sep 17 00:00:00 2001 From: Lucas Rodriguez Date: Mon, 9 Oct 2023 20:27:37 -0300 Subject: [PATCH] Only rollback if there was a failure --- server/datastore/mysql/query_results.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/server/datastore/mysql/query_results.go b/server/datastore/mysql/query_results.go index e4691e0372e2..958cf273f0d7 100644 --- a/server/datastore/mysql/query_results.go +++ b/server/datastore/mysql/query_results.go @@ -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 } @@ -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") + } } }()