grpc-js: Fix pick_first handling of IDLE subchannels. Also stop reporting IDLE on LB creation

This commit is contained in:
Michael Lumish 2020-05-08 10:30:56 -07:00
parent ed608f897c
commit 3d8c9af401
3 changed files with 25 additions and 2 deletions

View File

@ -130,7 +130,6 @@ export class PickFirstLoadBalancer implements LoadBalancer {
* this load balancer's owner.
*/
constructor(private channelControlHelper: ChannelControlHelper) {
this.updateState(ConnectivityState.IDLE, new QueuePicker(this));
this.subchannelStateCounts = {
[ConnectivityState.CONNECTING]: 0,
[ConnectivityState.IDLE]: 0,
@ -168,6 +167,8 @@ export class PickFirstLoadBalancer implements LoadBalancer {
* basic IDLE state where there is no subchannel list to avoid
* holding unused resources */
this.resetSubchannelList();
this.updateState(ConnectivityState.IDLE, new QueuePicker(this));
return;
}
if (this.currentPick === null) {
if (this.triedAllSubchannels) {

View File

@ -95,7 +95,6 @@ export class RoundRobinLoadBalancer implements LoadBalancer {
private currentReadyPicker: RoundRobinPicker | null = null;
constructor(private channelControlHelper: ChannelControlHelper) {
this.updateState(ConnectivityState.IDLE, new QueuePicker(this));
this.subchannelStateCounts = {
[ConnectivityState.CONNECTING]: 0,
[ConnectivityState.IDLE]: 0,

View File

@ -69,3 +69,26 @@ describe('Client', () => {
}, deadline - Date.now());
});
});
describe('Client without a server', () => {
let client: Client;
before(() => {
// Arbitrary target that should not have a running server
client = new Client('localhost:12345', clientInsecureCreds);
});
after(() => {
client.close();
});
it('should fail multiple calls to the nonexistent server', done => {
// Regression test for https://github.com/grpc/grpc-node/issues/1411
client.makeUnaryRequest('/service/method', x => x, x => x, Buffer.from([]), (error, value) => {
assert(error);
assert.strictEqual(error?.code, grpc.status.UNAVAILABLE);
client.makeUnaryRequest('/service/method', x => x, x => x, Buffer.from([]), (error, value) => {
assert(error);
assert.strictEqual(error?.code, grpc.status.UNAVAILABLE);
done();
});
});
});
});