Skip to content

Commit

Permalink
fix(kuma-cp): fix conn closed error on transaction rollback (#10665)
Browse files Browse the repository at this point in the history
Signed-off-by: Marcin Skalski <skalskimarcin33@gmail.com>
  • Loading branch information
Automaat committed Jun 28, 2024
1 parent aa2d1ee commit 3503ad1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/core/resources/store/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ func InTx(ctx context.Context, transactions Transactions, fn func(ctx context.Co
if err != nil {
return err
}
if err := fn(CtxWithTx(ctx, tx)); err != nil {
// if context was canceled during transaction, pgx will close connection. So we should not run Rollback,
// as it will end up with "conn closed" error
if err := fn(CtxWithTx(ctx, tx)); err != nil && !errors.Is(err, context.Canceled) {
if rollbackErr := tx.Rollback(ctx); rollbackErr != nil {
return multierr.Append(errors.Wrap(rollbackErr, "could not rollback transaction"), err)
}
Expand Down

0 comments on commit 3503ad1

Please sign in to comment.