Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crdb: better max retry errors (especially with retries disabled) #1537

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/authzed/spicedb/pull/1537/files#diff-1b011b67a73f910b9841c71da8f83c3c99da6101f476e4d02bfb3d3335eda548R261

this will set the correct maxretries if it's been set to something other than the default (0 in the case of disabled)

}

// 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