From 0be7d923dc995aadde3187ede8f1f3e04f3b1383 Mon Sep 17 00:00:00 2001 From: Kyle Havlovitz Date: Wed, 20 Jul 2022 14:26:52 -0700 Subject: [PATCH] Cancel upstream watches when the discovery chain has been removed --- agent/proxycfg/ingress_gateway.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/agent/proxycfg/ingress_gateway.go b/agent/proxycfg/ingress_gateway.go index 3fb67ddabc..3889bdba87 100644 --- a/agent/proxycfg/ingress_gateway.go +++ b/agent/proxycfg/ingress_gateway.go @@ -148,6 +148,16 @@ func (s *handlerIngressGateway) handleUpdate(ctx context.Context, u UpdateEvent, for uid, cancelFn := range snap.IngressGateway.WatchedDiscoveryChains { if _, ok := watchedSvcs[uid]; !ok { + for targetID, cancelUpstreamFn := range snap.IngressGateway.WatchedUpstreams[uid] { + s.logger.Debug("stopping watch of target", + "upstream", uid, + "target", targetID, + ) + delete(snap.IngressGateway.WatchedUpstreams[uid], targetID) + delete(snap.IngressGateway.WatchedUpstreamEndpoints[uid], targetID) + cancelUpstreamFn() + } + cancelFn() delete(snap.IngressGateway.WatchedDiscoveryChains, uid) }