Skip to content

CsdsService not properly synchronized with XdsClient #8642

@ejona86

Description

@ejona86

Consider this code from CsdsService:

static ClientConfig getClientConfigForXdsClient(XdsClient xdsClient) {
ListenersConfigDump ldsConfig = dumpLdsConfig(
xdsClient.getSubscribedResourcesMetadata(ResourceType.LDS),
xdsClient.getCurrentVersion(ResourceType.LDS));

The initial issue is that getSubscribedResourcesMetadata() and getCurrentVersion() have no synchronization:

Map<String, ResourceMetadata> getSubscribedResourcesMetadata(ResourceType type) {
Map<String, ResourceMetadata> metadataMap = new HashMap<>();
for (Map.Entry<String, ResourceSubscriber> entry : getSubscribedResourcesMap(type).entrySet()) {
metadataMap.put(entry.getKey(), entry.getValue().metadata);
}
return metadataMap;
}

// Must be synchronized.
String getCurrentVersion(ResourceType type) {

That is bad. However, the xdsClient API itself is insufficient for CSDS because those two method calls need to be atomic; even if each of those methods were thread-safe the version needs to match the resources returned.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions