Skip to content

Commit f8338c5

Browse files
authored
Merge pull request #2784 from murgatroid99/grpc-js_pick_first_reconnection_fix
grpc-js: Fix pick_first reconnecting without active calls
2 parents 023c1d0 + a5fac6f commit f8338c5

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
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.10.10",
3+
"version": "1.10.11",
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/load-balancer-pick-first.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
PickResultType,
3333
UnavailablePicker,
3434
} from './picker';
35-
import { Endpoint, SubchannelAddress } from './subchannel-address';
35+
import { Endpoint, SubchannelAddress, subchannelAddressToString } from './subchannel-address';
3636
import * as logging from './logging';
3737
import { LogVerbosity } from './constants';
3838
import {
@@ -348,7 +348,6 @@ export class PickFirstLoadBalancer implements LoadBalancer {
348348
if (newState !== ConnectivityState.READY) {
349349
this.removeCurrentPick();
350350
this.calculateAndReportNewState();
351-
this.requestReresolution();
352351
}
353352
return;
354353
}
@@ -483,6 +482,15 @@ export class PickFirstLoadBalancer implements LoadBalancer {
483482
subchannel: this.channelControlHelper.createSubchannel(address, {}),
484483
hasReportedTransientFailure: false,
485484
}));
485+
trace('connectToAddressList([' + addressList.map(address => subchannelAddressToString(address)) + '])');
486+
for (const { subchannel } of newChildrenList) {
487+
if (subchannel.getConnectivityState() === ConnectivityState.READY) {
488+
this.channelControlHelper.addChannelzChild(subchannel.getChannelzRef());
489+
subchannel.addConnectivityStateListener(this.subchannelStateListener);
490+
this.pickSubchannel(subchannel);
491+
return;
492+
}
493+
}
486494
/* Ref each subchannel before resetting the list, to ensure that
487495
* subchannels shared between the list don't drop to 0 refs during the
488496
* transition. */
@@ -494,10 +502,6 @@ export class PickFirstLoadBalancer implements LoadBalancer {
494502
this.children = newChildrenList;
495503
for (const { subchannel } of this.children) {
496504
subchannel.addConnectivityStateListener(this.subchannelStateListener);
497-
if (subchannel.getConnectivityState() === ConnectivityState.READY) {
498-
this.pickSubchannel(subchannel);
499-
return;
500-
}
501505
}
502506
for (const child of this.children) {
503507
if (
@@ -527,6 +531,7 @@ export class PickFirstLoadBalancer implements LoadBalancer {
527531
const rawAddressList = ([] as SubchannelAddress[]).concat(
528532
...endpointList.map(endpoint => endpoint.addresses)
529533
);
534+
trace('updateAddressList([' + rawAddressList.map(address => subchannelAddressToString(address)) + '])');
530535
if (rawAddressList.length === 0) {
531536
throw new Error('No addresses in endpoint list passed to pick_first');
532537
}

0 commit comments

Comments
 (0)