mirror of https://github.com/grpc/grpc-node.git
grpc-js: pick_first: Properly dispose of current pick when it disconnects
This commit is contained in:
parent
698d1427c6
commit
66cd8519bd
|
@ -223,6 +223,21 @@ export class PickFirstLoadBalancer implements LoadBalancer {
|
||||||
this.calculateAndReportNewState();
|
this.calculateAndReportNewState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private removeCurrentPick() {
|
||||||
|
if (this.currentPick !== null) {
|
||||||
|
/* Unref can cause a state change, which can cause a change in the value
|
||||||
|
* of this.currentPick, so we hold a local reference to make sure that
|
||||||
|
* does not impact this function. */
|
||||||
|
const currentPick = this.currentPick;
|
||||||
|
this.currentPick = null;
|
||||||
|
currentPick.unref();
|
||||||
|
currentPick.removeConnectivityStateListener(this.subchannelStateListener);
|
||||||
|
this.channelControlHelper.removeChannelzChild(
|
||||||
|
currentPick.getChannelzRef()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private onSubchannelStateUpdate(
|
private onSubchannelStateUpdate(
|
||||||
subchannel: SubchannelInterface,
|
subchannel: SubchannelInterface,
|
||||||
previousState: ConnectivityState,
|
previousState: ConnectivityState,
|
||||||
|
@ -230,7 +245,7 @@ export class PickFirstLoadBalancer implements LoadBalancer {
|
||||||
) {
|
) {
|
||||||
if (this.currentPick?.realSubchannelEquals(subchannel)) {
|
if (this.currentPick?.realSubchannelEquals(subchannel)) {
|
||||||
if (newState !== ConnectivityState.READY) {
|
if (newState !== ConnectivityState.READY) {
|
||||||
this.currentPick = null;
|
this.removeCurrentPick();
|
||||||
this.calculateAndReportNewState();
|
this.calculateAndReportNewState();
|
||||||
this.channelControlHelper.requestReresolution();
|
this.channelControlHelper.requestReresolution();
|
||||||
}
|
}
|
||||||
|
@ -415,17 +430,7 @@ export class PickFirstLoadBalancer implements LoadBalancer {
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
this.resetSubchannelList();
|
this.resetSubchannelList();
|
||||||
if (this.currentPick !== null) {
|
this.removeCurrentPick();
|
||||||
/* Unref can cause a state change, which can cause a change in the value
|
|
||||||
* of this.currentPick, so we hold a local reference to make sure that
|
|
||||||
* does not impact this function. */
|
|
||||||
const currentPick = this.currentPick;
|
|
||||||
currentPick.unref();
|
|
||||||
currentPick.removeConnectivityStateListener(this.subchannelStateListener);
|
|
||||||
this.channelControlHelper.removeChannelzChild(
|
|
||||||
currentPick.getChannelzRef()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getTypeName(): string {
|
getTypeName(): string {
|
||||||
|
|
Loading…
Reference in New Issue