retry

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func Backoff(attempt int) time.Duration

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

func Do[T any](ctx context.Context, retries int, op func() (T, error)) (T, error)

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 DoErr

func DoErr(ctx context.Context, retries int, op func() error) error

DoErr is Do for operations with no result value.

func IsTransient

func IsTransient(err error) bool

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL