@@ -314,21 +314,22 @@ func deDupAddresses(addrs []resolver.Address) []resolver.Address {
314
314
return retAddrs
315
315
}
316
316
317
+ // reconcileSubConnsLocked updates the active subchannels based on a new address
318
+ // list from the resolver. It does this by:
319
+ // - closing subchannels: any existing subchannels associated with addresses
320
+ // that are no longer in the updated list are shut down.
321
+ // - removing subchannels: entries for these closed subchannels are removed
322
+ // from the subchannel map.
323
+ //
324
+ // This ensures that the subchannel map accurately reflects the current set of
325
+ // addresses received from the name resolver.
317
326
func (b * pickfirstBalancer ) reconcileSubConnsLocked (newAddrs []resolver.Address ) {
318
- // Remove old subConns that were not in new address list.
319
- oldAddrsMap := resolver .NewAddressMap ()
320
- for _ , k := range b .subConns .Keys () {
321
- oldAddrsMap .Set (k , true )
322
- }
323
-
324
- // Flatten the new endpoint addresses.
325
327
newAddrsMap := resolver .NewAddressMap ()
326
328
for _ , addr := range newAddrs {
327
329
newAddrsMap .Set (addr , true )
328
330
}
329
331
330
- // Shut them down and remove them.
331
- for _ , oldAddr := range oldAddrsMap .Keys () {
332
+ for _ , oldAddr := range b .subConns .Keys () {
332
333
if _ , ok := newAddrsMap .Get (oldAddr ); ok {
333
334
continue
334
335
}
0 commit comments