From 0556bd8622ad672e343cbcbf911a848af5027afa Mon Sep 17 00:00:00 2001 From: Easwar Swaminathan Date: Thu, 3 Aug 2023 10:50:52 -0700 Subject: [PATCH] xdsclient: make watch timer a no-op if authority is closed --- xds/internal/xdsclient/authority.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/xds/internal/xdsclient/authority.go b/xds/internal/xdsclient/authority.go index 61adf794e9b7..6ad61dae4ae4 100644 --- a/xds/internal/xdsclient/authority.go +++ b/xds/internal/xdsclient/authority.go @@ -83,6 +83,7 @@ type authority struct { // actual state of the resource. resourcesMu sync.Mutex resources map[xdsresource.Type]map[string]*resourceState + closed bool } // authorityArgs is a convenience struct to wrap arguments required to create a @@ -443,6 +444,10 @@ func (a *authority) unrefLocked() int { func (a *authority) close() { a.transport.Close() + + a.resourcesMu.Lock() + a.closed = true + a.resourcesMu.Unlock() } func (a *authority) watchResource(rType xdsresource.Type, resourceName string, watcher xdsresource.ResourceWatcher) func() { @@ -507,10 +512,14 @@ func (a *authority) watchResource(rType xdsresource.Type, resourceName string, w } func (a *authority) handleWatchTimerExpiry(rType xdsresource.Type, resourceName string, state *resourceState) { - a.logger.Warningf("Watch for resource %q of type %s timed out", resourceName, rType.TypeName()) a.resourcesMu.Lock() defer a.resourcesMu.Unlock() + if a.closed { + return + } + a.logger.Warningf("Watch for resource %q of type %s timed out", resourceName, rType.TypeName()) + switch state.wState { case watchStateRequested: // This is the only state where we need to handle the timer expiry by