@@ -196,6 +196,26 @@ func (info *statusInfo) orderResponseWatches() {
196196 sort .Sort (info .orderedWatches )
197197}
198198
199+ // getOrderedWatches creates and returns a local copy of ordered watch keys.
200+ // This avoids race conditions by not using a shared struct field.
201+ func (info * statusInfo ) getOrderedWatches () keys {
202+ orderedWatches := make (keys , len (info .watches ))
203+
204+ var index int
205+ for id , watch := range info .watches {
206+ orderedWatches [index ] = key {
207+ ID : id ,
208+ TypeURL : watch .Request .GetTypeUrl (),
209+ }
210+ index ++
211+ }
212+
213+ // Sort our list which we can use in the SetSnapshot functions.
214+ // This is only run when we enable ADS on the cache.
215+ sort .Sort (orderedWatches )
216+ return orderedWatches
217+ }
218+
199219// orderResponseDeltaWatches will track a list of delta watch keys and order them if
200220// true is passed.
201221func (info * statusInfo ) orderResponseDeltaWatches () {
@@ -214,3 +234,23 @@ func (info *statusInfo) orderResponseDeltaWatches() {
214234 // This is only run when we enable ADS on the cache.
215235 sort .Sort (info .orderedDeltaWatches )
216236}
237+
238+ // getOrderedDeltaWatches creates and returns a local copy of ordered delta watch keys.
239+ // This avoids race conditions by not using a shared struct field.
240+ func (info * statusInfo ) getOrderedDeltaWatches () keys {
241+ orderedWatches := make (keys , len (info .deltaWatches ))
242+
243+ var index int
244+ for id , deltaWatch := range info .deltaWatches {
245+ orderedWatches [index ] = key {
246+ ID : id ,
247+ TypeURL : deltaWatch .Request .GetTypeUrl (),
248+ }
249+ index ++
250+ }
251+
252+ // Sort our list which we can use in the SetSnapshot functions.
253+ // This is only run when we enable ADS on the cache.
254+ sort .Sort (orderedWatches )
255+ return orderedWatches
256+ }
0 commit comments