Skip to content

Commit 6614ebb

Browse files
authored
Merge pull request #2369 from murgatroid99/grpc-js_pick_first_fix
grpc-js: Fix bugs in pick first LB policy and channel subchannel wrapper
2 parents 72b99a1 + 6862af2 commit 6614ebb

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

packages/grpc-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@grpc/grpc-js",
3-
"version": "1.8.9",
3+
"version": "1.8.10",
44
"description": "gRPC Library for Node - pure JS implementation",
55
"homepage": "https://grpc.io/",
66
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",

packages/grpc-js/src/internal-channel.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,14 @@ const DEFAULT_RETRY_BUFFER_SIZE_BYTES = 1<<24; // 16 MB
8686
const DEFAULT_PER_RPC_RETRY_BUFFER_SIZE_BYTES = 1<<20; // 1 MB
8787

8888
class ChannelSubchannelWrapper extends BaseSubchannelWrapper implements SubchannelInterface {
89-
private stateListeners: ConnectivityStateListener[] = [];
9089
private refCount = 0;
90+
private subchannelStateListener: ConnectivityStateListener;
9191
constructor(childSubchannel: SubchannelInterface, private channel: InternalChannel) {
9292
super(childSubchannel);
93-
childSubchannel.addConnectivityStateListener((subchannel, previousState, newState, keepaliveTime) => {
93+
this.subchannelStateListener = (subchannel, previousState, newState, keepaliveTime) => {
9494
channel.throttleKeepalive(keepaliveTime);
95-
for (const listener of this.stateListeners) {
96-
listener(this, previousState, newState, keepaliveTime);
97-
}
98-
});
95+
};
96+
childSubchannel.addConnectivityStateListener(this.subchannelStateListener);
9997
}
10098

10199
ref(): void {
@@ -107,6 +105,7 @@ class ChannelSubchannelWrapper extends BaseSubchannelWrapper implements Subchann
107105
this.child.unref();
108106
this.refCount -= 1;
109107
if (this.refCount <= 0) {
108+
this.child.removeConnectivityStateListener(this.subchannelStateListener);
110109
this.channel.removeWrappedSubchannel(this);
111110
}
112111
}

packages/grpc-js/src/load-balancer-pick-first.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
} from './picker';
3434
import {
3535
SubchannelAddress,
36+
subchannelAddressEqual,
3637
subchannelAddressToString,
3738
} from './subchannel-address';
3839
import * as logging from './logging';
@@ -168,7 +169,7 @@ export class PickFirstLoadBalancer implements LoadBalancer {
168169
* connecting to the next one instead of waiting for the connection
169170
* delay timer. */
170171
if (
171-
subchannel === this.subchannels[this.currentSubchannelIndex] &&
172+
subchannel.getRealSubchannel() === this.subchannels[this.currentSubchannelIndex].getRealSubchannel() &&
172173
newState === ConnectivityState.TRANSIENT_FAILURE
173174
) {
174175
this.startNextSubchannelConnecting();
@@ -420,7 +421,7 @@ export class PickFirstLoadBalancer implements LoadBalancer {
420421
if (
421422
this.subchannels.length === 0 ||
422423
!this.latestAddressList.every(
423-
(value, index) => addressList[index] === value
424+
(value, index) => subchannelAddressEqual(addressList[index], value)
424425
)
425426
) {
426427
this.latestAddressList = addressList;

0 commit comments

Comments
 (0)