GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - codeGROOVE-dev/retry: Production-ready retry library for Go

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

307 Commits
307 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
examples
examples
 
 
.gitignore
.gitignore
 
 
.golangci.yml
.golangci.yml
 
 
.yamllint
.yamllint
 
 
LICENSE
LICENSE
 
 
Makefile
Makefile
 
 
README.md
README.md
 
 
VERSION
VERSION
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
options.go
options.go
 
 
retry.go
retry.go
 
 
retry_test.go
retry_test.go
 
 

Repository files navigation

retry: Production Retry Logic for Go

Release Software License Go Report Card Go Reference

Modern fork of avast/retry-go/v4 focused on correctness, reliability and efficiency. 100% API-compatible drop-in replacement.

Production guarantees:

  • Memory bounded: Max 1000 errors stored (configurable via maxErrors constant)
  • No goroutine leaks: Uses caller's goroutine exclusively
  • Integer overflow safe: Backoff capped at 2^62 to prevent wraparound
  • Context-aware: Cancellation checked before each attempt
  • No panics: All edge cases return errors
  • Predictable jitter: Uses math/rand/v2 for consistent performance
  • Zero allocations after init in success path

Quick Start

Installation

go get github.com/codeGROOVE-dev/retry

Simple Retry

// Retry a flaky operation up to 10 times (default)
err := retry.Do(func() error {
    return doSomethingFlaky()
})

Retry with Custom Attempts

// Retry up to 5 times with exponential backoff
err := retry.Do(
    func() error {
        resp, err := http.Get("https://api.example.com/data")
        if err != nil {
            return err
        }
        defer resp.Body.Close()
        return nil
    },
    retry.Attempts(5),
)

Overly-complicated production configuration

// Overly-complex production pattern: bounded retries with circuit breaking
err := retry.Do(
    func() error {
        return processPayment(ctx, req)
    },
    retry.Attempts(3),                        // Hard limit
    retry.Context(ctx),                       // Respect cancellation
    retry.MaxDelay(10*time.Second),           // Cap backoff
    retry.AttemptsForError(0, ErrRateLimit),  // Stop on rate limit
    retry.OnRetry(func(n uint, err error) {
        log.Printf("retry attempt %d: %v", n, err)
    }),
    retry.RetryIf(func(err error) bool {
        // Only retry on network errors
        var netErr net.Error
        return errors.As(err, &netErr) && netErr.Temporary()
    }),
)

Preventing Cascading Failures

// Stop retry storms with Unrecoverable
if errors.Is(err, context.DeadlineExceeded) {
    return retry.Unrecoverable(err) // Don't retry timeouts
}

// Per-error type limits prevent thundering herd
retry.AttemptsForError(0, ErrCircuitOpen)    // Fail fast on circuit breaker
retry.AttemptsForError(1, sql.ErrTxDone)     // One retry for tx errors
retry.AttemptsForError(5, ErrServiceUnavailable) // More retries for 503s

Changes from avast/retry-go/v4

This fork will always be a 100% compatible drop-in replacement. There are some minor tweaks that have been made though:

New APIs added:

  • UntilSucceeded() Option - Convenience wrapper for Attempts(0) (infinite retries)
  • FullJitterBackoffDelay() Strategy - New delay type with full jitter exponential backoff
  • WrapContextErrorWithLastError() Option - Wraps context errors with last function error
  • IfFunc Type - New stutter-proof name (RetryIfFunc is now an alias)

Safety improvements:

  • Memory bounded: Max 1000 errors (prevents OOM)
  • Uses math/rand/v2 (no lock contention)
  • Overflow protection: Backoff capped at 2^62
  • Enhanced validation and nil checks
  • Better context cancellation with context.Cause()

Documentation

  • API Docs
  • Examples
  • Tests

About

Production-ready retry library for Go

godoc.org/github.com/codeGROOVE-dev/retry

Topics

golang-libraryreliabilityretryretry-library

Resources

Readme
MIT license
Activity
Custom properties

Stars

12 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.