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 f8cda78 commit 8ba5930
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 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
8 changes: 6 additions & 2 deletions internal/datastore/crdb/pool/slqerrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package pool

import (
"errors"
"strconv"
"fmt"

"github.com/jackc/pgx/v5/pgconn"
)
Expand All @@ -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 fmt.Sprintf("max retries reached (%d): %s", e.MaxRetries, 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 8ba5930

Please sign in to comment.