@@ -186,10 +186,12 @@ func (b *Balancer) applyDiscoveredEndpoints(ctx context.Context, newest []endpoi
186
186
)
187
187
previous = b .connections ().All ()
188
188
)
189
+
190
+ _ , added , dropped := xslices .Diff (previous , newest , func (lhs , rhs endpoint.Endpoint ) int {
191
+ return strings .Compare (lhs .Address (), rhs .Address ())
192
+ })
193
+
189
194
defer func () {
190
- _ , added , dropped := xslices .Diff (previous , newest , func (lhs , rhs endpoint.Endpoint ) int {
191
- return strings .Compare (lhs .Address (), rhs .Address ())
192
- })
193
195
onDone (
194
196
xslices .Transform (newest , func (t endpoint.Endpoint ) trace.EndpointInfo { return t }),
195
197
xslices .Transform (added , func (t endpoint.Endpoint ) trace.EndpointInfo { return t }),
@@ -202,6 +204,7 @@ func (b *Balancer) applyDiscoveredEndpoints(ctx context.Context, newest []endpoi
202
204
for _ , c := range connections {
203
205
b .pool .Allow (ctx , c )
204
206
c .Endpoint ().Touch ()
207
+ _ = c .Ping (ctx )
205
208
}
206
209
207
210
info := balancerConfig.Info {SelfLocation : localDC }
@@ -213,6 +216,13 @@ func (b *Balancer) applyDiscoveredEndpoints(ctx context.Context, newest []endpoi
213
216
}
214
217
215
218
b .connectionsState .Store (state )
219
+
220
+ for _ , e := range dropped {
221
+ c := b .pool .GetIfPresent (e )
222
+ if c != nil {
223
+ _ = c .Close (ctx )
224
+ }
225
+ }
216
226
}
217
227
218
228
func (b * Balancer ) Close (ctx context.Context ) (err error ) {
0 commit comments