Skip to content

Commit c1815e0

Browse files
committed
grpc-js: Fix pick_first reconnecting without active calls
1 parent c934257 commit c1815e0

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 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,13 @@ 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.pickSubchannel(subchannel);
489+
return;
490+
}
491+
}
486492
/* Ref each subchannel before resetting the list, to ensure that
487493
* subchannels shared between the list don't drop to 0 refs during the
488494
* transition. */
@@ -527,6 +533,7 @@ export class PickFirstLoadBalancer implements LoadBalancer {
527533
const rawAddressList = ([] as SubchannelAddress[]).concat(
528534
...endpointList.map(endpoint => endpoint.addresses)
529535
);
536+
trace('updateAddressList([' + rawAddressList.map(address => subchannelAddressToString(address)) + '])');
530537
if (rawAddressList.length === 0) {
531538
throw new Error('No addresses in endpoint list passed to pick_first');
532539
}

0 commit comments

Comments
 (0)