Skip to content

Commit

Permalink
sqlite: increase retries
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Aug 1, 2023
1 parent e42253a commit ccba68a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions persist/sqlite/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (s *Store) queryRow(query string, args ...any) *loggedRow {
func (s *Store) transaction(fn func(txn) error) error {
var err error
log := s.log.Named("transaction")
for i := 1; i <= 10; i++ {
for i := 1; i <= 15; i++ {
start := time.Now()
log := log.With(zap.Int("attempt", i))
err = doTransaction(s.db, log, fn)
Expand All @@ -98,7 +98,7 @@ func (s *Store) transaction(fn func(txn) error) error {
return err
}
log.Debug("database locked", zap.Duration("elapsed", time.Since(start)), zap.Stack("stack"))
sleep := time.Duration(math.Pow(2, float64(i))) * time.Millisecond
sleep := time.Duration(math.Pow(2, float64(i))) * time.Millisecond // exponential backoff for a total of ~30s
time.Sleep(sleep + time.Duration(rand.Int63n(int64(sleep)/10)))
}
return fmt.Errorf("transaction failed: %w", err)
Expand Down

0 comments on commit ccba68a

Please sign in to comment.