Skip to content

Commit

Permalink
fix aeraki memory leak when node info update (#399)
Browse files Browse the repository at this point in the history
* fix aeraki memory leak when node info update
Signed-off-by: shenyixiong <[email protected]>

* fix aeraki memory leak when reconnect to istiod
Signed-off-by: shenyixiong <[email protected]>

---------

Co-authored-by: shenyixiong <[email protected]>
  • Loading branch information
shencurl521 and shenyixiong authored Dec 12, 2023
1 parent c429093 commit b9fb430
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
10 changes: 4 additions & 6 deletions internal/controller/istio/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}()
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions internal/xds/cache_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions internal/xds/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions internal/xds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b9fb430

Please sign in to comment.