diff --git a/balancer/grpclb/grpclb.go b/balancer/grpclb/grpclb.go index 3df3f9d97d68..5b2c3f242392 100644 --- a/balancer/grpclb/grpclb.go +++ b/balancer/grpclb/grpclb.go @@ -37,6 +37,7 @@ import ( lbpb "google.golang.org/grpc/balancer/grpclb/grpc_lb_v1" "google.golang.org/grpc/connectivity" "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/internal/backoff" "google.golang.org/grpc/resolver" ) @@ -46,6 +47,23 @@ const ( grpclbName = "grpclb" ) +var ( + // defaultBackoffConfig configures the backoff strategy that's used when the + // init handshake in the RPC is unsuccessful. It's not for the clientconn + // reconnect backoff. + // + // It has the same value as the default grpc.DefaultBackoffConfig. Note that + // grpc.DefaultBackoffConfig can actually change, but this won't. + // + // TODO: make backoff configurable. + defaultBackoffConfig = backoff.Config{ + MaxDelay: 120 * time.Second, + BaseDelay: 1.0 * time.Second, + Factor: 1.6, + Jitter: 0.2, + } +) + func convertDuration(d *durationpb.Duration) time.Duration { if d == nil { return 0 @@ -147,7 +165,7 @@ func (b *lbBuilder) Build(cc balancer.ClientConn, opt balancer.BuildOptions) bal scStates: make(map[balancer.SubConn]connectivity.State), picker: &errPicker{err: balancer.ErrNoSubConnAvailable}, clientStats: newRPCStats(), - backoff: grpc.DefaultBackoffConfig, // TODO: make backoff configurable + backoff: defaultBackoffConfig, // TODO: make backoff configurable. } return lb @@ -167,7 +185,7 @@ type lbBalancer struct { // The ClientConn to talk to the remote balancer. ccRemoteLB *grpc.ClientConn // backoff for calling remote balancer. - backoff grpc.BackoffConfig + backoff backoff.Config // Support client side load reporting. Each picker gets a reference to this, // and will update its content. diff --git a/balancer/grpclb/grpclb_remote_balancer.go b/balancer/grpclb/grpclb_remote_balancer.go index cba2f47dc69f..fb4c117b5c15 100644 --- a/balancer/grpclb/grpclb_remote_balancer.go +++ b/balancer/grpclb/grpclb_remote_balancer.go @@ -238,7 +238,7 @@ func (lb *lbBalancer) watchRemoteBalancer() { continue } - timer := time.NewTimer(lb.backoff.backoff(retryCount)) + timer := time.NewTimer(lb.backoff.Backoff(retryCount)) select { case <-timer.C: case <-lb.doneCh: