Skip to content

Commit be06f82

Browse files
committed
Merge remote-tracking branch 'upstream/@grpc/[email protected]' into v1.4.x_upmerge_1
2 parents aeb4273 + 2767660 commit be06f82

File tree

6 files changed

+54
-36
lines changed

6 files changed

+54
-36
lines changed

packages/grpc-js-xds/interop/xds-interop-client.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ class CallStatsTracker {
130130

131131
private subscribers: CallSubscriber[] = [];
132132

133+
private removeSubscriber(subscriber: CallSubscriber) {
134+
const index = this.subscribers.indexOf(subscriber);
135+
if (index >= 0) {
136+
this.subscribers.splice(index, 1);
137+
}
138+
}
139+
133140
getCallStats(callCount: number, timeoutSec: number): Promise<LoadBalancerStatsResponse> {
134141
return new Promise((resolve, reject) => {
135142
let finished = false;
@@ -142,7 +149,7 @@ class CallStatsTracker {
142149
setTimeout(() => {
143150
if (!finished) {
144151
finished = true;
145-
this.subscribers.splice(this.subscribers.indexOf(subscriber), 1);
152+
this.removeSubscriber(subscriber);
146153
resolve(subscriber.getFinalStats());
147154
}
148155
}, timeoutSec * 1000)
@@ -155,7 +162,7 @@ class CallStatsTracker {
155162
for (const subscriber of callSubscribers) {
156163
subscriber.addCallStarted();
157164
if (!subscriber.needsMoreCalls()) {
158-
this.subscribers.splice(this.subscribers.indexOf(subscriber), 1);
165+
this.removeSubscriber(subscriber);
159166
}
160167
}
161168
return {

packages/grpc-js-xds/scripts/xds.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ GRPC_NODE_TRACE=xds_client,xds_resolver,cds_balancer,eds_balancer,priority,weigh
5959
--gcp_suffix=$(date '+%s') \
6060
--verbose \
6161
${XDS_V3_OPT-} \
62-
--client_cmd="$(which node) grpc-node/packages/grpc-js-xds/build/interop/xds-interop-client \
62+
--client_cmd="$(which node) --enable-source-maps grpc-node/packages/grpc-js-xds/build/interop/xds-interop-client \
6363
--server=xds:///{server_uri} \
6464
--stats_port={stats_port} \
6565
--qps={qps} \

packages/grpc-js-xds/src/xds-bootstrap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function validateXdsServerConfig(obj: any): XdsServerConfig {
109109
return {
110110
serverUri: obj.server_uri,
111111
channelCreds: obj.channel_creds.map(validateChannelCredsConfig),
112-
serverFeatures: obj.server_features
112+
serverFeatures: obj.server_features ?? []
113113
};
114114
}
115115

packages/grpc-js-xds/src/xds-client.ts

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,16 @@ export class XdsClient {
341341
return;
342342
}
343343
trace('Loaded bootstrap info: ' + JSON.stringify(bootstrapInfo, undefined, 2));
344+
if (bootstrapInfo.xdsServers.length < 1) {
345+
trace('Failed to initialize xDS Client. No servers provided in bootstrap info.');
346+
// Bubble this error up to any listeners
347+
this.reportStreamError({
348+
code: status.INTERNAL,
349+
details: 'Failed to initialize xDS Client. No servers provided in bootstrap info.',
350+
metadata: new Metadata(),
351+
});
352+
return;
353+
}
344354
if (bootstrapInfo.xdsServers[0].serverFeatures.indexOf('xds_v3') >= 0) {
345355
this.apiVersion = XdsApiVersion.V3;
346356
} else {
@@ -425,8 +435,7 @@ export class XdsClient {
425435
{channelOverride: channel}
426436
);
427437
this.maybeStartLrsStream();
428-
},
429-
(error) => {
438+
}).catch((error) => {
430439
trace('Failed to initialize xDS Client. ' + error.message);
431440
// Bubble this error up to any listeners
432441
this.reportStreamError({
@@ -507,13 +516,15 @@ export class XdsClient {
507516
}
508517
}
509518

510-
private handleAdsCallError(error: ServiceError) {
519+
private handleAdsCallStatus(streamStatus: StatusObject) {
511520
trace(
512-
'ADS stream ended. code=' + error.code + ' details= ' + error.details
521+
'ADS stream ended. code=' + streamStatus.code + ' details= ' + streamStatus.details
513522
);
514523
this.adsCallV2 = null;
515524
this.adsCallV3 = null;
516-
this.reportStreamError(error);
525+
if (streamStatus.code !== status.OK) {
526+
this.reportStreamError(streamStatus);
527+
}
517528
/* If the backoff timer is no longer running, we do not need to wait any
518529
* more to start the new call. */
519530
if (!this.adsBackoff.isRunning()) {
@@ -535,9 +546,10 @@ export class XdsClient {
535546
this.adsCallV2.on('data', (message: DiscoveryResponse__Output) => {
536547
this.handleAdsResponse(message);
537548
});
538-
this.adsCallV2.on('error', (error: ServiceError) => {
539-
this.handleAdsCallError(error);
549+
this.adsCallV2.on('status', (status: StatusObject) => {
550+
this.handleAdsCallStatus(status);
540551
});
552+
this.adsCallV2.on('error', () => {});
541553
return true;
542554
}
543555

@@ -555,9 +567,10 @@ export class XdsClient {
555567
this.adsCallV3.on('data', (message: DiscoveryResponse__Output) => {
556568
this.handleAdsResponse(message);
557569
});
558-
this.adsCallV3.on('error', (error: ServiceError) => {
559-
this.handleAdsCallError(error);
570+
this.adsCallV3.on('status', (status: StatusObject) => {
571+
this.handleAdsCallStatus(status);
560572
});
573+
this.adsCallV3.on('error', () => {});
561574
return true;
562575
}
563576

@@ -763,9 +776,9 @@ export class XdsClient {
763776
this.receivedLrsSettingsForCurrentStream = true;
764777
}
765778

766-
private handleLrsCallError(error: ServiceError) {
779+
private handleLrsCallStatus(streamStatus: StatusObject) {
767780
trace(
768-
'LRS stream ended. code=' + error.code + ' details= ' + error.details
781+
'LRS stream ended. code=' + streamStatus.code + ' details= ' + streamStatus.details
769782
);
770783
this.lrsCallV2 = null;
771784
this.lrsCallV3 = null;
@@ -789,9 +802,10 @@ export class XdsClient {
789802
this.lrsCallV2.on('data', (message: LoadStatsResponse__Output) => {
790803
this.handleLrsResponse(message);
791804
});
792-
this.lrsCallV2.on('error', (error: ServiceError) => {
793-
this.handleLrsCallError(error);
805+
this.lrsCallV2.on('status', (status: StatusObject) => {
806+
this.handleLrsCallStatus(status);
794807
});
808+
this.lrsCallV2.on('error', () => {});
795809
return true;
796810
}
797811

@@ -807,9 +821,10 @@ export class XdsClient {
807821
this.lrsCallV3.on('data', (message: LoadStatsResponse__Output) => {
808822
this.handleLrsResponse(message);
809823
});
810-
this.lrsCallV3.on('error', (error: ServiceError) => {
811-
this.handleLrsCallError(error);
824+
this.lrsCallV3.on('status', (status: StatusObject) => {
825+
this.handleLrsCallStatus(status);
812826
});
827+
this.lrsCallV3.on('error', () => {});
813828
return true;
814829
}
815830

packages/grpc-js/src/channel.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,8 @@ export class ChannelImplementation implements Channel {
177177
);
178178
}
179179
if (options) {
180-
if (
181-
typeof options !== 'object' ||
182-
!Object.values(options).every(
183-
(value) =>
184-
typeof value === 'string' ||
185-
typeof value === 'number' ||
186-
typeof value === 'undefined'
187-
)
188-
) {
189-
throw new TypeError(
190-
'Channel options must be an object with string or number values'
191-
);
180+
if (typeof options !== 'object') {
181+
throw new TypeError('Channel options must be an object');
192182
}
193183
}
194184
const originalTargetUri = parseUri(target);

packages/grpc-js/src/server.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ export class Server {
268268
};
269269
}
270270

271+
const deferredCallback = (error: Error | null, port: number) => {
272+
process.nextTick(() => callback(error, port));
273+
}
274+
271275
const setupServer = (): http2.Http2Server | http2.Http2SecureServer => {
272276
let http2Server: http2.Http2Server | http2.Http2SecureServer;
273277
if (creds._isSecure()) {
@@ -309,6 +313,7 @@ export class Server {
309313
const http2Server = setupServer();
310314
return new Promise<number | Error>((resolve, reject) => {
311315
function onError(err: Error): void {
316+
trace('Failed to bind ' + subchannelAddressToString(address) + ' with error ' + err.message);
312317
resolve(err);
313318
}
314319

@@ -356,6 +361,7 @@ export class Server {
356361
const http2Server = setupServer();
357362
return new Promise<BindResult>((resolve, reject) => {
358363
function onError(err: Error): void {
364+
trace('Failed to bind ' + subchannelAddressToString(address) + ' with error ' + err.message);
359365
resolve(bindWildcardPort(addressList.slice(1)));
360366
}
361367

@@ -384,7 +390,7 @@ export class Server {
384390
// We only want one resolution result. Discard all future results
385391
resolverListener.onSuccessfulResolution = () => {};
386392
if (addressList.length === 0) {
387-
callback(new Error(`No addresses resolved for port ${port}`), 0);
393+
deferredCallback(new Error(`No addresses resolved for port ${port}`), 0);
388394
return;
389395
}
390396
let bindResultPromise: Promise<BindResult>;
@@ -407,26 +413,26 @@ export class Server {
407413
if (bindResult.count === 0) {
408414
const errorString = `No address added out of total ${addressList.length} resolved`;
409415
logging.log(LogVerbosity.ERROR, errorString);
410-
callback(new Error(errorString), 0);
416+
deferredCallback(new Error(errorString), 0);
411417
} else {
412418
if (bindResult.count < addressList.length) {
413419
logging.log(
414420
LogVerbosity.INFO,
415421
`WARNING Only ${bindResult.count} addresses added out of total ${addressList.length} resolved`
416422
);
417423
}
418-
callback(null, bindResult.port);
424+
deferredCallback(null, bindResult.port);
419425
}
420426
},
421427
(error) => {
422428
const errorString = `No address added out of total ${addressList.length} resolved`;
423429
logging.log(LogVerbosity.ERROR, errorString);
424-
callback(new Error(errorString), 0);
430+
deferredCallback(new Error(errorString), 0);
425431
}
426432
);
427433
},
428434
onError: (error) => {
429-
callback(new Error(error.details), 0);
435+
deferredCallback(new Error(error.details), 0);
430436
},
431437
};
432438

0 commit comments

Comments
 (0)