Back to

Package rpcretry

Latest Go to latest

The latest major version is .

Published: Aug 30, 2020 | License: MIT | Module:


Package rpcretry automatically retries when some RPCs end in error. RPC sometimes fails rarely and this may be able to recover simply by retrying.

Non idempotency operations (Commit, Rollback, and Next) are not automatically retried.

By default, it retries up to 3 times. First wait 100 milliseconds, then wait exponentially back off. This value can be changed by option.

Example (HowToUse)


package main

import (

func main() {
	ctx := context.Background()
	client, err := clouddatastore.FromContext(ctx)
	if err != nil {
	defer client.Close()
	defer testutils.CleanUpAllEntities(ctx, client)

	mw := rpcretry.New(
		// rpcretry.WithMaxDoublings(2),



func New

func New(opts ...RetryOption) datastore.Middleware

New automatically RPC retry middleware creates & returns.

type RetryOption

type RetryOption interface {

A RetryOption is an retry option for a retry middleware.

func WithLogf

func WithLogf(logf func(ctx context.Context, format string, args ...interface{})) RetryOption

WithLogf creates a ClientOption that uses the specified logger.

Deprecated: use WithLogger instead.

func WithLogger

func WithLogger(logf func(ctx context.Context, format string, args ...interface{})) RetryOption

WithLogger creates a ClientOption that uses the specified logger.

func WithMaxBackoffDuration

func WithMaxBackoffDuration(d time.Duration) RetryOption

WithMaxBackoffDuration specified maximum duratiuon of retry backoff.

func WithMaxDoublings

func WithMaxDoublings(maxDoublings int) RetryOption

WithMaxDoublings specifies how many times the waiting time should be doubled.

func WithMinBackoffDuration

func WithMinBackoffDuration(d time.Duration) RetryOption

WithMinBackoffDuration specified minimal duration of retry backoff.

func WithRetryLimit

func WithRetryLimit(limit int) RetryOption

WithRetryLimit provides retry limit when RPC failed.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier