@@ -142,12 +142,17 @@ func (edsImpl *edsBalancerImpl) handleChildPolicy(name string, config json.RawMe
142142 continue
143143 }
144144 for lid , config := range bgwc .configs {
145+ lidJSON , err := lid .ToString ()
146+ if err != nil {
147+ edsImpl .logger .Errorf ("failed to marshal LocalityID: %#v, skipping this locality" , lid )
148+ continue
149+ }
145150 // TODO: (eds) add support to balancer group to support smoothly
146151 // switching sub-balancers (keep old balancer around until new
147152 // balancer becomes ready).
148- bgwc .bg .Remove (lid . String () )
149- bgwc .bg .Add (lid . String () , edsImpl .subBalancerBuilder )
150- bgwc .bg .UpdateClientConnState (lid . String () , balancer.ClientConnState {
153+ bgwc .bg .Remove (lidJSON )
154+ bgwc .bg .Add (lidJSON , edsImpl .subBalancerBuilder )
155+ bgwc .bg .UpdateClientConnState (lidJSON , balancer.ClientConnState {
151156 ResolverState : resolver.State {Addresses : config .addrs },
152157 })
153158 // This doesn't need to manually update picker, because the new
@@ -285,6 +290,11 @@ func (edsImpl *edsBalancerImpl) handleEDSResponsePerPriority(bgwc *balancerGroup
285290 // One balancer for each locality.
286291
287292 lid := locality .ID
293+ lidJSON , err := lid .ToString ()
294+ if err != nil {
295+ edsImpl .logger .Errorf ("failed to marshal LocalityID: %#v, skipping this locality" , lid )
296+ continue
297+ }
288298 newLocalitiesSet [lid ] = struct {}{}
289299
290300 newWeight := locality .Weight
@@ -319,8 +329,8 @@ func (edsImpl *edsBalancerImpl) handleEDSResponsePerPriority(bgwc *balancerGroup
319329 config , ok := bgwc .configs [lid ]
320330 if ! ok {
321331 // A new balancer, add it to balancer group and balancer map.
322- bgwc .stateAggregator .Add (lid . String () , newWeight )
323- bgwc .bg .Add (lid . String () , edsImpl .subBalancerBuilder )
332+ bgwc .stateAggregator .Add (lidJSON , newWeight )
333+ bgwc .bg .Add (lidJSON , edsImpl .subBalancerBuilder )
324334 config = & localityConfig {
325335 weight : newWeight ,
326336 }
@@ -343,23 +353,28 @@ func (edsImpl *edsBalancerImpl) handleEDSResponsePerPriority(bgwc *balancerGroup
343353
344354 if weightChanged {
345355 config .weight = newWeight
346- bgwc .stateAggregator .UpdateWeight (lid . String () , newWeight )
356+ bgwc .stateAggregator .UpdateWeight (lidJSON , newWeight )
347357 rebuildStateAndPicker = true
348358 }
349359
350360 if addrsChanged {
351361 config .addrs = newAddrs
352- bgwc .bg .UpdateClientConnState (lid . String () , balancer.ClientConnState {
362+ bgwc .bg .UpdateClientConnState (lidJSON , balancer.ClientConnState {
353363 ResolverState : resolver.State {Addresses : newAddrs },
354364 })
355365 }
356366 }
357367
358368 // Delete localities that are removed in the latest response.
359369 for lid := range bgwc .configs {
370+ lidJSON , err := lid .ToString ()
371+ if err != nil {
372+ edsImpl .logger .Errorf ("failed to marshal LocalityID: %#v, skipping this locality" , lid )
373+ continue
374+ }
360375 if _ , ok := newLocalitiesSet [lid ]; ! ok {
361- bgwc .stateAggregator .Remove (lid . String () )
362- bgwc .bg .Remove (lid . String () )
376+ bgwc .stateAggregator .Remove (lidJSON )
377+ bgwc .bg .Remove (lidJSON )
363378 delete (bgwc .configs , lid )
364379 edsImpl .logger .Infof ("Locality %v deleted" , lid )
365380 rebuildStateAndPicker = true
0 commit comments