#9457·grpc-go

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

  1. Replace the mutable StreamBackoff package globals and init() functions in xdsclient.go and lrsclient.go with an unexported backoff func(int) time.Duration field on xdsclient.Config and lrsclient.Config (defaulting to defaultExponentialBackoff when nil).
  2. Provide an internal helper in xdsclientinternal / lrsclientinternal (or export Config.Backoff if desired for external callers) so tests in xdsclient/test can configure per-client backoff on Config without mutating global state.

Alternatives Considered

  • Exposing Backoff func(int) time.Duration directly on Config: allows external callers to customize stream backoff, though an unexported field with an internal test helper is sufficient if we do not want func(int) time.Duration in the public API.
  • Keeping the init()-populated StreamBackoff global variable.

Additional Context

Part of #9455.