Skip to content

Commit 9655fa5

Browse files
committed
xds:fix cancel xds watcher accidentally removes the url
1 parent eb391fd commit 9655fa5

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

xds/src/main/java/io/grpc/xds/XdsClientImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,13 @@ public void run() {
332332
if (!subscriber.isWatched()) {
333333
subscriber.cancelResourceWatch();
334334
resourceSubscribers.get(type).remove(resourceName);
335-
subscribedResourceTypeUrls.remove(type.typeUrl());
336335
if (subscriber.xdsChannel != null) {
337336
subscriber.xdsChannel.adjustResourceSubscription(type);
338337
}
339338
if (resourceSubscribers.get(type).isEmpty()) {
340339
resourceSubscribers.remove(type);
340+
subscribedResourceTypeUrls.remove(type.typeUrl());
341+
341342
}
342343
}
343344
}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,33 @@ public void ldsResourceUpdated() {
938938
assertThat(channelForEmptyAuthority).isNull();
939939
}
940940

941+
@Test
942+
public void ldsResourceUpdated_() {
943+
DiscoveryRpcCall call = startResourceWatcher(XdsListenerResource.getInstance(), LDS_RESOURCE,
944+
ldsResourceWatcher);
945+
verifyResourceMetadataRequested(LDS, LDS_RESOURCE);
946+
947+
// Initial LDS response.
948+
call.sendResponse(LDS, testListenerVhosts, VERSION_1, "0000");
949+
call.verifyRequest(LDS, LDS_RESOURCE, VERSION_1, "0000", NODE);
950+
verify(ldsResourceWatcher).onChanged(ldsUpdateCaptor.capture());
951+
verifyGoldenListenerVhosts(ldsUpdateCaptor.getValue());
952+
verifyResourceMetadataAcked(LDS, LDS_RESOURCE, testListenerVhosts, VERSION_1, TIME_INCREMENT);
953+
954+
xdsClient.watchXdsResource(XdsListenerResource.getInstance(),
955+
LDS_RESOURCE + "1", ldsResourceWatcher);
956+
xdsClient.cancelXdsResourceWatch(XdsListenerResource.getInstance(), LDS_RESOURCE + "1",ldsResourceWatcher);
957+
958+
// Updated LDS response.
959+
Any testListenerVhosts2 = Any.pack(mf.buildListenerWithApiListener(LDS_RESOURCE,
960+
mf.buildRouteConfiguration("new", mf.buildOpaqueVirtualHosts(VHOST_SIZE))));
961+
call.sendResponse(LDS, testListenerVhosts2, VERSION_2, "0001");
962+
call.verifyRequest(LDS, LDS_RESOURCE, VERSION_2, "0001", NODE);
963+
verify(ldsResourceWatcher).onChanged(ldsUpdateCaptor.capture());
964+
verifyGoldenListenerVhosts(ldsUpdateCaptor.getValue());
965+
verifyResourceMetadataAcked(LDS, LDS_RESOURCE, testListenerVhosts2, VERSION_2, TIME_INCREMENT * 2);
966+
}
967+
941968
@Test
942969
public void ldsResourceUpdated_withXdstpResourceName() {
943970
BootstrapperImpl.enableFederation = true;

0 commit comments

Comments
 (0)