Skip to content

Commit

Permalink
xds: Preserve nonce when unsubscribing type
Browse files Browse the repository at this point in the history
This fixes a regression introduced in 19c9b99.

b/374697875
  • Loading branch information
ejona86 authored Jan 3, 2025
1 parent 9a712c3 commit 1cf1927
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 7 additions & 3 deletions xds/src/main/java/io/grpc/xds/client/ControlPlaneClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,10 @@ void adjustResourceSubscription(XdsResourceType<?> resourceType) {
resourceStore.startMissingResourceTimers(resources, resourceType);

if (resources.isEmpty()) {
// The resource type no longer has subscribing resources; clean up references to it
// The resource type no longer has subscribing resources; clean up references to it, except
// for nonces. If the resource type becomes used again the control plane can ignore requests
// for old/missing nonces. Old type's nonces are dropped when the ADS stream is restarted.
versions.remove(resourceType);
adsStream.respNonces.remove(resourceType);
}
}

Expand Down Expand Up @@ -313,7 +314,10 @@ private class AdsStream implements XdsTransportFactory.EventHandler<DiscoveryRes
// Nonce in each response is echoed back in the following ACK/NACK request. It is
// used for management server to identify which response the client is ACKing/NACking.
// To avoid confusion, client-initiated requests will always use the nonce in
// most recently received responses of each resource type.
// most recently received responses of each resource type. Nonces are never deleted from the
// map; nonces are only discarded once the stream closes because xds_protocol says "the
// management server should not send a DiscoveryResponse for any DiscoveryRequest that has a
// stale nonce."
private final Map<XdsResourceType<?>, String> respNonces = new HashMap<>();
private final StreamingCall<DiscoveryRequest, DiscoveryResponse> call;
private final MethodDescriptor<DiscoveryRequest, DiscoveryResponse> methodDescriptor =
Expand Down
5 changes: 2 additions & 3 deletions xds/src/test/java/io/grpc/xds/GrpcXdsClientImplTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -2899,10 +2899,9 @@ public void edsCleanupNonceAfterUnsubscription() {
verifySubscribedResourcesMetadataSizes(0, 0, 0, 0);
call.verifyRequest(EDS, Arrays.asList(), VERSION_1, "0000", NODE);

// When re-subscribing, the version and nonce were properly forgotten, so the request is the
// same as the initial request
// When re-subscribing, the version was forgotten but not the nonce
xdsClient.watchXdsResource(XdsEndpointResource.getInstance(), "A.1", edsResourceWatcher);
call.verifyRequest(EDS, "A.1", "", "", NODE, Mockito.timeout(2000).times(2));
call.verifyRequest(EDS, "A.1", "", "0000", NODE, Mockito.timeout(2000));
}

@Test
Expand Down

0 comments on commit 1cf1927

Please sign in to comment.