Skip to content

Commit

Permalink
pgsql: fix RunInTxContext when retry exceed (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
acoshift authored Jan 22, 2021
1 parent 1f776f3 commit eb94dfc
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ func RunInTxContext(ctx context.Context, db BeginTxer, opts *TxOptions, fn func(
return tx.Commit()
}

var err error
for i := 0; i < option.MaxAttempts; i++ {
err := f()
err = f()
if err == nil || errors.Is(err, ErrAbortTx) {
return nil
}
Expand All @@ -84,5 +85,5 @@ func RunInTxContext(ctx context.Context, db BeginTxer, opts *TxOptions, fn func(
}
}

return nil
return err
}

0 comments on commit eb94dfc

Please sign in to comment.