Skip to content

Commit 8b015fa

Browse files
committed
xds/xdsdepmgr: skip unsubscribeFromCluster after Close
The unsubscribe closure returned by SubscribeToCluster is wrapped in sync.OnceFunc and may run from the balancer tree Close after DependencyManager.Close has already torn everything down and dropped m.watcher. Before this change, the post-Close invocation reached maybeSendUpdateLocked and panicked on m.watcher.Update. Add an m.stopped guard at the top of unsubscribeFromCluster to match the pattern used by every other post-Close callback in this file. Restores the test/xds suite that started failing after 80dac1c.
1 parent 80dac1c commit 8b015fa

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

internal/xds/xdsdepmgr/xds_dependency_manager.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,13 @@ func (m *DependencyManager) SubscribeToCluster(name string) func() {
10051005
func (m *DependencyManager) unsubscribeFromCluster(name string) {
10061006
m.mu.Lock()
10071007
defer m.mu.Unlock()
1008+
// Balancers can invoke the unsubscribe closure returned by
1009+
// SubscribeToCluster after Close has already torn down all watchers and
1010+
// dropped m.watcher / m.xdsClient. Match the m.stopped guard used by
1011+
// every other post-Close callback in this file.
1012+
if m.stopped {
1013+
return
1014+
}
10081015
c := m.clusterSubscriptions[name]
10091016
c.dynamicRefCount--
10101017
// This should not happen as unsubscribe returned from the

0 commit comments

Comments
 (0)