Skip to content

Commit 7fe25f7

Browse files
committed
xds: Preserve nonce when unsubscribing type
This fixes a regression introduced in 19c9b99. b/374697875
1 parent 32877ea commit 7fe25f7

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,10 @@ void adjustResourceSubscription(XdsResourceType<?> resourceType) {
155155
}
156156
adsStream.sendDiscoveryRequest(resourceType, resources);
157157
if (resources.isEmpty()) {
158-
// The resource type no longer has subscribing resources; clean up references to it
158+
// The resource type no longer has subscribing resources; clean up references to it, except
159+
// for nonces. If the resource type becomes used again the control plane can ignore requests
160+
// for old/missing nonces. Old type's nonces are dropped when the ADS stream is restarted.
159161
versions.remove(resourceType);
160-
adsStream.respNonces.remove(resourceType);
161162
}
162163
}
163164

@@ -270,7 +271,10 @@ private class AdsStream implements EventHandler<DiscoveryResponse> {
270271
// Nonce in each response is echoed back in the following ACK/NACK request. It is
271272
// used for management server to identify which response the client is ACKing/NACking.
272273
// To avoid confusion, client-initiated requests will always use the nonce in
273-
// most recently received responses of each resource type.
274+
// most recently received responses of each resource type. Nonces are never deleted from the
275+
// map; nonces are only discarded once the stream closes because xds_protocol says "the
276+
// management server should not send a DiscoveryResponse for any DiscoveryRequest that has a
277+
// stale nonce."
274278
private final Map<XdsResourceType<?>, String> respNonces = new HashMap<>();
275279
private final StreamingCall<DiscoveryRequest, DiscoveryResponse> call;
276280
private final MethodDescriptor<DiscoveryRequest, DiscoveryResponse> methodDescriptor =

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2782,10 +2782,9 @@ public void edsCleanupNonceAfterUnsubscription() {
27822782
verifySubscribedResourcesMetadataSizes(0, 0, 0, 0);
27832783
call.verifyRequest(EDS, Arrays.asList(), VERSION_1, "0000", NODE);
27842784

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

27912790
@Test

0 commit comments

Comments
 (0)