From e6da08525c8814953b1f46728ff0a52b70aae99c Mon Sep 17 00:00:00 2001 From: shenyixiong Date: Thu, 30 Nov 2023 15:14:37 +0800 Subject: [PATCH 1/2] fix aeraki memory leak when node info update Signed-off-by: shenyixiong --- internal/xds/cache_mgr.go | 4 ++++ internal/xds/callbacks.go | 1 + internal/xds/server.go | 1 + 3 files changed, 6 insertions(+) diff --git a/internal/xds/cache_mgr.go b/internal/xds/cache_mgr.go index 960962806..a84db9b28 100644 --- a/internal/xds/cache_mgr.go +++ b/internal/xds/cache_mgr.go @@ -455,6 +455,10 @@ func (c *CacheMgr) initNode(_ string) { c.pushChannel <- istiomodel.EventUpdate } +func (c *CacheMgr) clearNode(node string) { + c.routeCache.ClearSnapshot(node) +} + func (c *CacheMgr) hasNode(node string) bool { if _, err := c.routeCache.GetSnapshot(node); err != nil { return false diff --git a/internal/xds/callbacks.go b/internal/xds/callbacks.go index ea7c5f367..19f4de65c 100644 --- a/internal/xds/callbacks.go +++ b/internal/xds/callbacks.go @@ -47,6 +47,7 @@ func (cb *callbacks) OnStreamOpen(_ context.Context, id int64, typ string) error } func (cb *callbacks) OnStreamClosed(id int64, node *core.Node) { xdsLog.Infof("node %s stream %d closed\n", node.Id, id) + cb.cacheMgr.clearNode(node.Id) } func (cb *callbacks) OnDeltaStreamOpen(_ context.Context, id int64, typ string) error { diff --git a/internal/xds/server.go b/internal/xds/server.go index 2bfb04966..5ca68cd71 100644 --- a/internal/xds/server.go +++ b/internal/xds/server.go @@ -35,6 +35,7 @@ type cacheMgr interface { initNode(node string) hasNode(node string) bool cache() cachev3.SnapshotCache + clearNode(node string) } // Server serves xDS resources to Envoy sidecars From ad8e5ff2786809f541277fb718e19075e630d311 Mon Sep 17 00:00:00 2001 From: shenyixiong Date: Thu, 30 Nov 2023 15:24:18 +0800 Subject: [PATCH 2/2] fix aeraki memory leak when reconnect to istiod Signed-off-by: shenyixiong --- internal/controller/istio/controller.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/internal/controller/istio/controller.go b/internal/controller/istio/controller.go index 69b988cb9..66490139f 100644 --- a/internal/controller/istio/controller.go +++ b/internal/controller/istio/controller.go @@ -84,10 +84,6 @@ func (c *Controller) Run(stop <-chan struct{}) { go c.configCache.Run(stop) go func() { c.connectIstio() - for { - time.Sleep(30 * time.Minute) - c.reconnectIstio() - } }() } @@ -125,9 +121,10 @@ func (c *Controller) connectIstio() { sm, err := c.newSecretManager() if err != nil { controllerLog.Errorf("failed to create SecretManager %s %v", c.options.IstiodAddr, err) - } else { - config.SecretManager = sm + time.Sleep(5 * time.Second) + continue } + config.SecretManager = sm } c.xdsMCP, err = adsc.New(c.options.IstiodAddr, &config) if err != nil { @@ -139,6 +136,7 @@ func (c *Controller) connectIstio() { c.xdsMCP.Store = configController if err = c.xdsMCP.Run(); err != nil { controllerLog.Errorf("adsc: failed running %v", err) + c.closeConnection() time.Sleep(5 * time.Second) continue }