Merge pull request #1413 from murgatroid99/grpc-js_pick_first_reconnect_fix

grpc-js: Fix pick_first handling of IDLE subchannels.
This commit is contained in:
Michael Lumish 2020-05-21 10:29:58 -07:00 committed by GitHub
commit 69d4116057
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@grpc/grpc-js",
"version": "1.0.3",
"version": "1.0.4",
"description": "gRPC Library for Node - pure JS implementation",
"homepage": "https://grpc.io/",
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",

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();
});
});
});
});