xds: Preserve nonce when unsubscribing type · grpc/grpc-java@1cf1927

File tree

2 files changed

lines changed

    • main/java/io/grpc/xds/client

2 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -167,9 +167,10 @@ void adjustResourceSubscription(XdsResourceType<?> resourceType) {

167167

resourceStore.startMissingResourceTimers(resources, resourceType);

168168
169169

if (resources.isEmpty()) {

170-

// The resource type no longer has subscribing resources; clean up references to it

170+

// The resource type no longer has subscribing resources; clean up references to it, except

171+

// for nonces. If the resource type becomes used again the control plane can ignore requests

172+

// for old/missing nonces. Old type's nonces are dropped when the ADS stream is restarted.

171173

versions.remove(resourceType);

172-

adsStream.respNonces.remove(resourceType);

173174

}

174175

}

175176

@@ -313,7 +314,10 @@ private class AdsStream implements XdsTransportFactory.EventHandler<DiscoveryRes

313314

// Nonce in each response is echoed back in the following ACK/NACK request. It is

314315

// used for management server to identify which response the client is ACKing/NACking.

315316

// To avoid confusion, client-initiated requests will always use the nonce in

316-

// most recently received responses of each resource type.

317+

// most recently received responses of each resource type. Nonces are never deleted from the

318+

// map; nonces are only discarded once the stream closes because xds_protocol says "the

319+

// management server should not send a DiscoveryResponse for any DiscoveryRequest that has a

320+

// stale nonce."

317321

private final Map<XdsResourceType<?>, String> respNonces = new HashMap<>();

318322

private final StreamingCall<DiscoveryRequest, DiscoveryResponse> call;

319323

private final MethodDescriptor<DiscoveryRequest, DiscoveryResponse> methodDescriptor =

Original file line numberDiff line numberDiff line change

@@ -2899,10 +2899,9 @@ public void edsCleanupNonceAfterUnsubscription() {

28992899

verifySubscribedResourcesMetadataSizes(0, 0, 0, 0);

29002900

call.verifyRequest(EDS, Arrays.asList(), VERSION_1, "0000", NODE);

29012901
2902-

// When re-subscribing, the version and nonce were properly forgotten, so the request is the

2903-

// same as the initial request

2902+

// When re-subscribing, the version was forgotten but not the nonce

29042903

xdsClient.watchXdsResource(XdsEndpointResource.getInstance(), "A.1", edsResourceWatcher);

2905-

call.verifyRequest(EDS, "A.1", "", "", NODE, Mockito.timeout(2000).times(2));

2904+

call.verifyRequest(EDS, "A.1", "", "0000", NODE, Mockito.timeout(2000));

29062905

}

29072906
29082907

@Test