From 3d8c9af40104de2809c00b540d91f0b999ecbea0 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Fri, 8 May 2020 10:30:56 -0700 Subject: [PATCH 1/2] grpc-js: Fix pick_first handling of IDLE subchannels. Also stop reporting IDLE on LB creation --- .../grpc-js/src/load-balancer-pick-first.ts | 3 ++- .../grpc-js/src/load-balancer-round-robin.ts | 1 - packages/grpc-js/test/test-client.ts | 23 +++++++++++++++++++ 3 files changed, 25 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 f3888618..c4f289a9 100644 --- a/packages/grpc-js/src/load-balancer-pick-first.ts +++ b/packages/grpc-js/src/load-balancer-pick-first.ts @@ -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) { diff --git a/packages/grpc-js/src/load-balancer-round-robin.ts b/packages/grpc-js/src/load-balancer-round-robin.ts index 51244341..9716d7f0 100644 --- a/packages/grpc-js/src/load-balancer-round-robin.ts +++ b/packages/grpc-js/src/load-balancer-round-robin.ts @@ -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, diff --git a/packages/grpc-js/test/test-client.ts b/packages/grpc-js/test/test-client.ts index da20c246..0d2878cb 100644 --- a/packages/grpc-js/test/test-client.ts +++ b/packages/grpc-js/test/test-client.ts @@ -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(); + }); + }); + }); +}); \ No newline at end of file From 8c61b166426993e944964c333cccd350e81046c3 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Fri, 8 May 2020 10:33:25 -0700 Subject: [PATCH 2/2] Bump grpc-js to 1.0.4 --- 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 3ca7b8f5..2ed5a8bf 100644 --- a/packages/grpc-js/package.json +++ b/packages/grpc-js/package.json @@ -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",