@@ -223,14 +223,29 @@ export class PickFirstLoadBalancer implements LoadBalancer {
223
223
this . calculateAndReportNewState ( ) ;
224
224
}
225
225
226
+ private removeCurrentPick ( ) {
227
+ if ( this . currentPick !== null ) {
228
+ /* Unref can cause a state change, which can cause a change in the value
229
+ * of this.currentPick, so we hold a local reference to make sure that
230
+ * does not impact this function. */
231
+ const currentPick = this . currentPick ;
232
+ this . currentPick = null ;
233
+ currentPick . unref ( ) ;
234
+ currentPick . removeConnectivityStateListener ( this . subchannelStateListener ) ;
235
+ this . channelControlHelper . removeChannelzChild (
236
+ currentPick . getChannelzRef ( )
237
+ ) ;
238
+ }
239
+ }
240
+
226
241
private onSubchannelStateUpdate (
227
242
subchannel : SubchannelInterface ,
228
243
previousState : ConnectivityState ,
229
244
newState : ConnectivityState
230
245
) {
231
246
if ( this . currentPick ?. realSubchannelEquals ( subchannel ) ) {
232
247
if ( newState !== ConnectivityState . READY ) {
233
- this . currentPick = null ;
248
+ this . removeCurrentPick ( ) ;
234
249
this . calculateAndReportNewState ( ) ;
235
250
this . channelControlHelper . requestReresolution ( ) ;
236
251
}
@@ -415,17 +430,7 @@ export class PickFirstLoadBalancer implements LoadBalancer {
415
430
416
431
destroy ( ) {
417
432
this . resetSubchannelList ( ) ;
418
- if ( this . currentPick !== null ) {
419
- /* Unref can cause a state change, which can cause a change in the value
420
- * of this.currentPick, so we hold a local reference to make sure that
421
- * does not impact this function. */
422
- const currentPick = this . currentPick ;
423
- currentPick . unref ( ) ;
424
- currentPick . removeConnectivityStateListener ( this . subchannelStateListener ) ;
425
- this . channelControlHelper . removeChannelzChild (
426
- currentPick . getChannelzRef ( )
427
- ) ;
428
- }
433
+ this . removeCurrentPick ( ) ;
429
434
}
430
435
431
436
getTypeName ( ) : string {
0 commit comments