Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] fix potential memory leak #10639

Open
wants to merge 11 commits into
base: v1.17.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/v1.17.25/fix-mem-lk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
changelog:
- type: FIX
issueLink: https://github.com/solo-io/solo-projects/issues/7805
resolvesIssue: false
description: Fixes a memory leak caused by an indefinitely growing map

20 changes: 16 additions & 4 deletions projects/gateway2/status/status_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,19 @@ func (f *statusSyncerFactory) QueueStatusForProxies(

// queue each proxy for a given sync iteration
for _, proxy := range proxiesToQueue {
proxyKey := getProxyNameNamespace(proxy)
// overwrite the sync count for the proxy with the most recent sync count
f.resyncsPerProxy[getProxyNameNamespace(proxy)] = totalSyncCount
f.resyncsPerProxy[proxyKey] = totalSyncCount

// keep track of proxies to check all proxies are handled in debugger
f.resyncsPerIteration[totalSyncCount] = append(f.resyncsPerIteration[totalSyncCount], getProxyNameNamespace(proxy))
f.resyncsPerIteration[totalSyncCount] = append(f.resyncsPerIteration[totalSyncCount], proxyKey)
}

// the plugin registry that produced the proxies is the same for all proxies in a given sync
f.registryPerSync[totalSyncCount] = pluginRegistry

delete(f.resyncsPerIteration, totalSyncCount-2)
delete(f.registryPerSync, totalSyncCount-2)
}

// HandleProxyReports is a callback that applies status plugins to the proxies that have been queued
Expand Down Expand Up @@ -108,7 +113,9 @@ func (f *statusSyncerFactory) HandleProxyReports(ctx context.Context, proxiesWit
continue
}

if f.resyncsPerIteration[proxySyncCount] == nil {
if len(f.resyncsPerIteration[proxySyncCount]) == 0 {
// remove the key so the map does not indefinitely grow
delete(f.resyncsPerIteration, proxySyncCount)
// re-sync already happened, nothing to do
continue
} else {
Expand All @@ -119,6 +126,11 @@ func (f *statusSyncerFactory) HandleProxyReports(ctx context.Context, proxiesWit
}
}
f.resyncsPerIteration[proxySyncCount] = updatedList

if len(f.resyncsPerIteration[proxySyncCount]) == 0 {
// remove the key so the map does not indefinitely grow
delete(f.resyncsPerIteration, proxySyncCount)
}
}

proxiesToReport[proxySyncCount] = append(proxiesToReport[proxySyncCount], proxyWithReport)
Expand All @@ -132,7 +144,7 @@ func (f *statusSyncerFactory) HandleProxyReports(ctx context.Context, proxiesWit
}

// If there are no more proxies for the sync iteration, delete the sync count
if len(f.resyncsPerIteration) == 0 {
if len(f.resyncsPerIteration[syncCount]) == 0 {
delete(f.registryPerSync, syncCount)
}
}
Expand Down
Loading