xds/clients: replace init() StreamBackoff global with per-client backoff on Config
Author: dashpoleCreated Sep 30, 2026Updated Sep 30, 2026
Use case(s) - what problem will this feature solve?
Currently in internal/xds/clients/xdsclient/xdsclient.go and internal/xds/clients/lrsclient/lrsclient.go, exponential stream backoff is wired via a mutable package global (xdsclientinternal.StreamBackoff = defaultExponentialBackoff and lrsclientinternal.StreamBackoff = defaultExponentialBackoff) inside an init() function.
Tests in xdsclient/test and lrsclient mutate this global variable directly to customize backoff behavior, which is not safe for parallel tests and relies on init() to wire default behavior.
Proposed Solution
- Replace the mutable
StreamBackoffpackage globals andinit()functions inxdsclient.goandlrsclient.gowith an unexportedbackoff func(int) time.Durationfield onxdsclient.Configandlrsclient.Config(defaulting todefaultExponentialBackoffwhennil). - Provide an internal helper in
xdsclientinternal/lrsclientinternal(or exportConfig.Backoffif desired for external callers) so tests inxdsclient/testcan configure per-client backoff onConfigwithout mutating global state.
Alternatives Considered
- Exposing
Backoff func(int) time.Durationdirectly onConfig: allows external callers to customize stream backoff, though an unexported field with an internal test helper is sufficient if we do not wantfunc(int) time.Durationin the public API. - Keeping the
init()-populatedStreamBackoffglobal variable.
Additional Context
Part of #9455.
Source: grpc/grpc-go