From 63f81a7be4bfac7ae0a3935ff241327823fd7160 Mon Sep 17 00:00:00 2001 From: Evan Cordell Date: Mon, 18 Sep 2023 13:25:51 -0400 Subject: [PATCH] crdb: better max retry errors (especially with retries disabled) --- internal/datastore/crdb/pool/pool.go | 2 +- internal/datastore/crdb/pool/slqerrors.go | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/datastore/crdb/pool/pool.go b/internal/datastore/crdb/pool/pool.go index 82fdd877af..a2c179357e 100644 --- a/internal/datastore/crdb/pool/pool.go +++ b/internal/datastore/crdb/pool/pool.go @@ -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. diff --git a/internal/datastore/crdb/pool/slqerrors.go b/internal/datastore/crdb/pool/slqerrors.go index ee688c9944..e1ab1be951 100644 --- a/internal/datastore/crdb/pool/slqerrors.go +++ b/internal/datastore/crdb/pool/slqerrors.go @@ -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.