Skip to content

Commit

Permalink
crdb: better max retry errors (especially with retries disabled)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecordell committed Sep 18, 2023
1 parent 652d309 commit b40a0d0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/datastore/crdb/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func (p *RetryPool) withRetries(ctx context.Context, fn func(conn *pgxpool.Conn)
log.Ctx(ctx).Warn().Err(err).Uint8("retries", retries).Msg("error is not resettable or retryable")
return err
}
return &MaxRetryError{MaxRetries: p.maxRetries, LastErr: err}
return &MaxRetryError{MaxRetries: maxRetries, LastErr: err}
}

// GC marks a connection for destruction on the next Acquire.
Expand Down
6 changes: 5 additions & 1 deletion internal/datastore/crdb/pool/slqerrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ type MaxRetryError struct {
}

func (e *MaxRetryError) Error() string {
return strconv.Itoa(int(e.MaxRetries)) + "max retries reached" + ": " + e.LastErr.Error()
if e.MaxRetries == 0 {
return "retries disabled: " + e.LastErr.Error()
}
return strconv.Itoa(int(e.MaxRetries)) + " max retries reached" + ": " + e.LastErr.Error()
}

func (e *MaxRetryError) Unwrap() error { return e.LastErr }

// ResettableError is an error that we think may succeed if retried against a new connection.
Expand Down

0 comments on commit b40a0d0

Please sign in to comment.