@@ -72,14 +72,23 @@ func (f *statusSyncerFactory) QueueStatusForProxies(
72
72
73
73
// queue each proxy for a given sync iteration
74
74
for _ , proxy := range proxiesToQueue {
75
+ proxyKey := getProxyNameNamespace (proxy )
75
76
// overwrite the sync count for the proxy with the most recent sync count
76
- f .resyncsPerProxy [getProxyNameNamespace ( proxy ) ] = totalSyncCount
77
+ f .resyncsPerProxy [proxyKey ] = totalSyncCount
77
78
78
79
// keep track of proxies to check all proxies are handled in debugger
79
- f .resyncsPerIteration [totalSyncCount ] = append (f .resyncsPerIteration [totalSyncCount ], getProxyNameNamespace ( proxy ) )
80
+ f .resyncsPerIteration [totalSyncCount ] = append (f .resyncsPerIteration [totalSyncCount ], proxyKey )
80
81
}
82
+
81
83
// the plugin registry that produced the proxies is the same for all proxies in a given sync
82
84
f .registryPerSync [totalSyncCount ] = pluginRegistry
85
+
86
+ // Set a max value of 5 for n-5 iterations. Ideally we should only care about n-1 but playing it safe.
87
+ // QueueStatusForProxies sets the entries in these maps, however the `proxy_sync_id` annotation on the proxy
88
+ // (which is used as the map key) can change between when this method and HandleProxyReports is called.
89
+ // This can result in the map indefinitely growing which is what the subsequent lines aim to stem.
90
+ delete (f .resyncsPerIteration , totalSyncCount - 5 )
91
+ delete (f .registryPerSync , totalSyncCount - 5 )
83
92
}
84
93
85
94
// HandleProxyReports is a callback that applies status plugins to the proxies that have been queued
@@ -108,7 +117,9 @@ func (f *statusSyncerFactory) HandleProxyReports(ctx context.Context, proxiesWit
108
117
continue
109
118
}
110
119
111
- if f .resyncsPerIteration [proxySyncCount ] == nil {
120
+ if len (f .resyncsPerIteration [proxySyncCount ]) == 0 {
121
+ // remove the key so the map does not indefinitely grow
122
+ delete (f .resyncsPerIteration , proxySyncCount )
112
123
// re-sync already happened, nothing to do
113
124
continue
114
125
} else {
@@ -119,6 +130,11 @@ func (f *statusSyncerFactory) HandleProxyReports(ctx context.Context, proxiesWit
119
130
}
120
131
}
121
132
f .resyncsPerIteration [proxySyncCount ] = updatedList
133
+
134
+ if len (f .resyncsPerIteration [proxySyncCount ]) == 0 {
135
+ // remove the key so the map does not indefinitely grow
136
+ delete (f .resyncsPerIteration , proxySyncCount )
137
+ }
122
138
}
123
139
124
140
proxiesToReport [proxySyncCount ] = append (proxiesToReport [proxySyncCount ], proxyWithReport )
@@ -132,7 +148,7 @@ func (f *statusSyncerFactory) HandleProxyReports(ctx context.Context, proxiesWit
132
148
}
133
149
134
150
// If there are no more proxies for the sync iteration, delete the sync count
135
- if len (f .resyncsPerIteration ) == 0 {
151
+ if len (f .resyncsPerIteration [ syncCount ] ) == 0 {
136
152
delete (f .registryPerSync , syncCount )
137
153
}
138
154
}
0 commit comments