From 2aec366508e8bb434efd081bea2256b1aeb3dc84 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Tue, 9 Mar 2021 10:39:42 -0800 Subject: [PATCH] grpc-js-xds: Fix sending stats when reestablishing LRS stream --- packages/grpc-js-xds/package.json | 2 +- packages/grpc-js-xds/src/xds-client.ts | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/grpc-js-xds/package.json b/packages/grpc-js-xds/package.json index 6ff858160..875c8645c 100644 --- a/packages/grpc-js-xds/package.json +++ b/packages/grpc-js-xds/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/grpc-js-xds", - "version": "1.2.3", + "version": "1.2.4", "description": "Plugin for @grpc/grpc-js. Adds the xds:// URL scheme and associated features.", "main": "build/src/index.js", "scripts": { diff --git a/packages/grpc-js-xds/src/xds-client.ts b/packages/grpc-js-xds/src/xds-client.ts index 56ddddf93..09420ba99 100644 --- a/packages/grpc-js-xds/src/xds-client.ts +++ b/packages/grpc-js-xds/src/xds-client.ts @@ -1020,12 +1020,14 @@ export class XdsClient { this.lrsBackoff.runOnce(); this.lrsCall = this.lrsClient.streamLoadStats(); + let receivedSettingsForThisStream = false; this.lrsCall.on('data', (message: LoadStatsResponse__Output) => { /* Once we get any response from the server, we assume that the stream is * in a good state, so we can reset the backoff timer. */ this.lrsBackoff.stop(); this.lrsBackoff.reset(); if ( + !receivedSettingsForThisStream || message.load_reporting_interval?.seconds !== this.latestLrsSettings?.load_reporting_interval?.seconds || message.load_reporting_interval?.nanos !== @@ -1045,13 +1047,13 @@ export class XdsClient { }, loadReportingIntervalMs); } this.latestLrsSettings = message; + receivedSettingsForThisStream = true; }); this.lrsCall.on('error', (error: ServiceError) => { trace( 'LRS stream ended. code=' + error.code + ' details= ' + error.details ); this.lrsCall = null; - this.latestLrsSettings = null; clearInterval(this.statsTimer); /* If the backoff timer is no longer running, we do not need to wait any * more to start the new call. */ @@ -1068,14 +1070,20 @@ export class XdsClient { if (!this.lrsCall) { return; } + if (!this.latestLrsSettings) { + this.lrsCall.write({ + node: this.lrsNode!, + }); + return; + } const clusterStats: ClusterStats[] = []; for (const [ { clusterName, edsServiceName }, stats, ] of this.clusterStatsMap.entries()) { if ( - this.latestLrsSettings!.send_all_clusters || - this.latestLrsSettings!.clusters.indexOf(clusterName) > 0 + this.latestLrsSettings.send_all_clusters || + this.latestLrsSettings.clusters.indexOf(clusterName) > 0 ) { const upstreamLocalityStats: UpstreamLocalityStats[] = []; for (const localityStats of stats.localityStats) {