diff --git a/packages/grpc-js/src/xds-client.ts b/packages/grpc-js/src/xds-client.ts index 98454817..ff4d36b8 100644 --- a/packages/grpc-js/src/xds-client.ts +++ b/packages/grpc-js/src/xds-client.ts @@ -105,6 +105,7 @@ export class XdsClient { > = new Map[]>(); private lastEdsVersionInfo = ''; private lastEdsNonce = ''; + private latestEdsResponses: ClusterLoadAssignment__Output[] = []; constructor( private targetName: string, @@ -206,6 +207,7 @@ export class XdsClient { } this.lastEdsVersionInfo = message.version_info; this.lastEdsNonce = message.nonce; + this.latestEdsResponses = edsResponses; this.ackEds(); break; } @@ -357,6 +359,18 @@ export class XdsClient { if (addedServiceName) { this.updateEdsNames(); } + + /* If we have already received an update for the requested edsServiceName, + * immediately pass that update along to the watcher */ + for (const message of this.latestEdsResponses) { + if (message.cluster_name === edsServiceName) { + /* These updates normally occur asynchronously, so we ensure that + * the same happens here */ + process.nextTick(() => { + watcher.onValidUpdate(message); + }); + } + } } removeEndpointWatcher(