Skip to content

Commit e3e343d

Browse files
committed
xds: Remember nonces for unknown types
If the control plane sends a resource type the client doesn't understand at-the-moment, the control plane will still expect the client to include the nonce if the client subscribes to the type in the future. This most easily happens when unsubscribing the last resource of a type. Which meant 1cf1927 was insufficient.
1 parent aba8a0c commit e3e343d

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

xds/src/main/java/io/grpc/xds/client/ControlPlaneClient.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ XdsResourceType<?> fromTypeUrl(String typeUrl) {
280280
private class AdsStream implements EventHandler<DiscoveryResponse> {
281281
private boolean responseReceived;
282282
private boolean closed;
283-
// Response nonce for the most recently received discovery responses of each resource type.
283+
// Response nonce for the most recently received discovery responses of each resource type URL.
284284
// Client initiated requests start response nonce with empty string.
285285
// Nonce in each response is echoed back in the following ACK/NACK request. It is
286286
// used for management server to identify which response the client is ACKing/NACking.
@@ -289,7 +289,7 @@ private class AdsStream implements EventHandler<DiscoveryResponse> {
289289
// map; nonces are only discarded once the stream closes because xds_protocol says "the
290290
// management server should not send a DiscoveryResponse for any DiscoveryRequest that has a
291291
// stale nonce."
292-
private final Map<XdsResourceType<?>, String> respNonces = new HashMap<>();
292+
private final Map<String, String> respNonces = new HashMap<>();
293293
private final StreamingCall<DiscoveryRequest, DiscoveryResponse> call;
294294
private final MethodDescriptor<DiscoveryRequest, DiscoveryResponse> methodDescriptor =
295295
AggregatedDiscoveryServiceGrpc.getStreamAggregatedResourcesMethod();
@@ -337,7 +337,7 @@ void sendDiscoveryRequest(XdsResourceType<?> type, String versionInfo,
337337
final void sendDiscoveryRequest(XdsResourceType<?> type, Collection<String> resources) {
338338
logger.log(XdsLogLevel.INFO, "Sending {0} request for resources: {1}", type, resources);
339339
sendDiscoveryRequest(type, versions.getOrDefault(type, ""), resources,
340-
respNonces.getOrDefault(type, ""), null);
340+
respNonces.getOrDefault(type.typeUrl(), ""), null);
341341
}
342342

343343
@Override
@@ -352,6 +352,7 @@ public void onRecvMessage(DiscoveryResponse response) {
352352
public void run() {
353353
// Reset flag as message has been received on a stream
354354
streamClosedNoResponse = false;
355+
respNonces.put(response.getTypeUrl(), response.getNonce());
355356
XdsResourceType<?> type = fromTypeUrl(response.getTypeUrl());
356357
if (logger.isLoggable(XdsLogLevel.DEBUG)) {
357358
logger.log(
@@ -387,7 +388,6 @@ final void handleRpcResponse(XdsResourceType<?> type, String versionInfo, List<A
387388
return;
388389
}
389390
responseReceived = true;
390-
respNonces.put(type, nonce);
391391
ProcessingTracker processingTracker = new ProcessingTracker(
392392
() -> call.startRecvMessage(), syncContext);
393393
xdsResponseHandler.handleResourceResponse(type, serverInfo, versionInfo, resources, nonce,

xds/src/test/java/io/grpc/xds/GrpcXdsClientImplTestBase.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -2898,10 +2898,13 @@ public void edsCleanupNonceAfterUnsubscription() {
28982898
xdsClient.cancelXdsResourceWatch(XdsEndpointResource.getInstance(), "A.1", edsResourceWatcher);
28992899
verifySubscribedResourcesMetadataSizes(0, 0, 0, 0);
29002900
call.verifyRequest(EDS, Arrays.asList(), VERSION_1, "0000", NODE);
2901+
// The control plane can send an updated response for the empty subscription list, with a new
2902+
// nonce.
2903+
call.sendResponse(EDS, Arrays.asList(), VERSION_1, "0001");
29012904

29022905
// When re-subscribing, the version was forgotten but not the nonce
29032906
xdsClient.watchXdsResource(XdsEndpointResource.getInstance(), "A.1", edsResourceWatcher);
2904-
call.verifyRequest(EDS, "A.1", "", "0000", NODE, Mockito.timeout(2000));
2907+
call.verifyRequest(EDS, "A.1", "", "0001", NODE, Mockito.timeout(2000));
29052908
}
29062909

29072910
@Test

0 commit comments

Comments
 (0)