From c1815e09e2ae44bfa00d1664433a2c9c80fed179 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Wed, 3 Jul 2024 15:22:03 -0700 Subject: [PATCH 1/3] grpc-js: Fix pick_first reconnecting without active calls --- packages/grpc-js/src/load-balancer-pick-first.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/grpc-js/src/load-balancer-pick-first.ts b/packages/grpc-js/src/load-balancer-pick-first.ts index f6c43b33d..e08853336 100644 --- a/packages/grpc-js/src/load-balancer-pick-first.ts +++ b/packages/grpc-js/src/load-balancer-pick-first.ts @@ -32,7 +32,7 @@ import { PickResultType, UnavailablePicker, } from './picker'; -import { Endpoint, SubchannelAddress } from './subchannel-address'; +import { Endpoint, SubchannelAddress, subchannelAddressToString } from './subchannel-address'; import * as logging from './logging'; import { LogVerbosity } from './constants'; import { @@ -348,7 +348,6 @@ export class PickFirstLoadBalancer implements LoadBalancer { if (newState !== ConnectivityState.READY) { this.removeCurrentPick(); this.calculateAndReportNewState(); - this.requestReresolution(); } return; } @@ -483,6 +482,13 @@ export class PickFirstLoadBalancer implements LoadBalancer { subchannel: this.channelControlHelper.createSubchannel(address, {}), hasReportedTransientFailure: false, })); + trace('connectToAddressList([' + addressList.map(address => subchannelAddressToString(address)) + '])'); + for (const { subchannel } of newChildrenList) { + if (subchannel.getConnectivityState() === ConnectivityState.READY) { + this.pickSubchannel(subchannel); + return; + } + } /* Ref each subchannel before resetting the list, to ensure that * subchannels shared between the list don't drop to 0 refs during the * transition. */ @@ -527,6 +533,7 @@ export class PickFirstLoadBalancer implements LoadBalancer { const rawAddressList = ([] as SubchannelAddress[]).concat( ...endpointList.map(endpoint => endpoint.addresses) ); + trace('updateAddressList([' + rawAddressList.map(address => subchannelAddressToString(address)) + '])'); if (rawAddressList.length === 0) { throw new Error('No addresses in endpoint list passed to pick_first'); } From e804ad65b652c90ba0c9223892ac48827879c97d Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Wed, 3 Jul 2024 15:37:40 -0700 Subject: [PATCH 2/3] grpc-js: Bump to 1.10.11 --- packages/grpc-js/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/grpc-js/package.json b/packages/grpc-js/package.json index 774a0eafd..23af2f981 100644 --- a/packages/grpc-js/package.json +++ b/packages/grpc-js/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/grpc-js", - "version": "1.10.10", + "version": "1.10.11", "description": "gRPC Library for Node - pure JS implementation", "homepage": "https://grpc.io/", "repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js", From a5fac6f0565e147cdc1cb3376e9509ef4d503e2e Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Mon, 8 Jul 2024 15:08:30 -0700 Subject: [PATCH 3/3] grpc-js: pick-first: Fix short circuit READY subchannel handling --- packages/grpc-js/src/load-balancer-pick-first.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/grpc-js/src/load-balancer-pick-first.ts b/packages/grpc-js/src/load-balancer-pick-first.ts index e08853336..e042e1161 100644 --- a/packages/grpc-js/src/load-balancer-pick-first.ts +++ b/packages/grpc-js/src/load-balancer-pick-first.ts @@ -485,6 +485,8 @@ export class PickFirstLoadBalancer implements LoadBalancer { trace('connectToAddressList([' + addressList.map(address => subchannelAddressToString(address)) + '])'); for (const { subchannel } of newChildrenList) { if (subchannel.getConnectivityState() === ConnectivityState.READY) { + this.channelControlHelper.addChannelzChild(subchannel.getChannelzRef()); + subchannel.addConnectivityStateListener(this.subchannelStateListener); this.pickSubchannel(subchannel); return; } @@ -500,10 +502,6 @@ export class PickFirstLoadBalancer implements LoadBalancer { this.children = newChildrenList; for (const { subchannel } of this.children) { subchannel.addConnectivityStateListener(this.subchannelStateListener); - if (subchannel.getConnectivityState() === ConnectivityState.READY) { - this.pickSubchannel(subchannel); - return; - } } for (const child of this.children) { if (