@@ -25,6 +25,7 @@ import (
25
25
"time"
26
26
27
27
"google.golang.org/grpc/internal"
28
+ "google.golang.org/grpc/internal/backoff"
28
29
"google.golang.org/grpc/internal/cache"
29
30
"google.golang.org/grpc/internal/grpcsync"
30
31
"google.golang.org/grpc/internal/xds/bootstrap"
@@ -53,16 +54,17 @@ const NameForServer = "#server"
53
54
// only when all references are released, and it is safe for the caller to
54
55
// invoke this close function multiple times.
55
56
func New (name string ) (XDSClient , func (), error ) {
56
- return newRefCounted (name , defaultWatchExpiryTimeout , defaultIdleAuthorityDeleteTimeout )
57
+ return newRefCounted (name , defaultWatchExpiryTimeout , defaultIdleAuthorityDeleteTimeout , backoff . DefaultExponential . Backoff )
57
58
}
58
59
59
60
// newClientImpl returns a new xdsClient with the given config.
60
- func newClientImpl (config * bootstrap.Config , watchExpiryTimeout time.Duration , idleAuthorityDeleteTimeout time.Duration ) (* clientImpl , error ) {
61
+ func newClientImpl (config * bootstrap.Config , watchExpiryTimeout time.Duration , idleAuthorityDeleteTimeout time.Duration , streamBackoff func ( int ) time. Duration ) (* clientImpl , error ) {
61
62
ctx , cancel := context .WithCancel (context .Background ())
62
63
c := & clientImpl {
63
64
done : grpcsync .NewEvent (),
64
65
config : config ,
65
66
watchExpiryTimeout : watchExpiryTimeout ,
67
+ backoff : streamBackoff ,
66
68
serializer : grpcsync .NewCallbackSerializer (ctx ),
67
69
serializerClose : cancel ,
68
70
resourceTypes : newResourceTypeRegistry (),
@@ -90,6 +92,11 @@ type OptionsForTesting struct {
90
92
// AuthorityIdleTimeout is the timeout before idle authorities are deleted.
91
93
// If unspecified, uses the default value used in non-test code.
92
94
AuthorityIdleTimeout time.Duration
95
+
96
+ // StreamBackoffAfterFailure is the backoff function used to determine the
97
+ // backoff duration after stream failures. If unspecified, uses the default
98
+ // value used in non-test code.
99
+ StreamBackoffAfterFailure func (int ) time.Duration
93
100
}
94
101
95
102
// NewForTesting returns an xDS client configured with the provided options.
@@ -111,11 +118,14 @@ func NewForTesting(opts OptionsForTesting) (XDSClient, func(), error) {
111
118
if opts .AuthorityIdleTimeout == 0 {
112
119
opts .AuthorityIdleTimeout = defaultIdleAuthorityDeleteTimeout
113
120
}
121
+ if opts .StreamBackoffAfterFailure == nil {
122
+ opts .StreamBackoffAfterFailure = defaultStreamBackoffFunc
123
+ }
114
124
115
125
if err := bootstrap .SetFallbackBootstrapConfig (opts .Contents ); err != nil {
116
126
return nil , nil , err
117
127
}
118
- client , cancel , err := newRefCounted (opts .Name , opts .WatchExpiryTimeout , opts .AuthorityIdleTimeout )
128
+ client , cancel , err := newRefCounted (opts .Name , opts .WatchExpiryTimeout , opts .AuthorityIdleTimeout , opts . StreamBackoffAfterFailure )
119
129
return client , func () { bootstrap .UnsetFallbackBootstrapConfigForTesting (); cancel () }, err
120
130
}
121
131
0 commit comments