Documentation
¶
Overview ¶
Package retry classifies PostgreSQL errors as transient or permanent and retries the transient ones with a capped backoff.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Backoff ¶
Backoff returns the exponential backoff for attempt n (0-based): 1s, 2s, 4s, 8s, 16s, then 30s. The exponent is capped BEFORE the shift: 2^n seconds overflows time.Duration (int64 nanoseconds) around n=34, yielding a negative delay that would fire immediately. 30s needs at most 2^5, so anything beyond is the cap.
func Do ¶
Do runs op up to retries+1 times, retrying only transient errors with exponential backoff. A permanent error, or an exhausted budget, returns the last error. ctx cancellation stops the loop.
op must be safe to re-run from scratch: the caller retries the whole operation, not a partial result.
func IsTransient ¶
IsTransient reports whether a connection/query error is worth retrying. Retrying a permanent error (bad password, missing database, syntax error) only delays the inevitable failure, so classification is explicit rather than "retry everything".
A PostgreSQL SQLSTATE decides it when present; otherwise the shared rules (network, deadline, the no-data sentinel) apply.
Types ¶
This section is empty.