java-topology/defects/grpc-java/patch/grpc-java-0002-xds-client-get-active-authorities-list-contains.patch

19 lines
1 KiB
Diff
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# UNDF: UNDF-2026-000000743
# UNDF: (leave blank)
--- a/xds/src/main/java/io/grpc/xds/client/XdsClientImpl.java
+++ b/xds/src/main/java/io/grpc/xds/client/XdsClientImpl.java
@@ -1091,9 +1091,7 @@ public final class XdsClientImpl extends XdsClient {
private Collection<String> getActiveAuthorities(ControlPlaneClient cpc) {
- List<String> asList = activatedCpClients.entrySet().stream()
+ // Always return a HashSet for O(1) contains(); linear scan over asList was O(A×S×T)
+ // inside double-loops in cleanUpResourceTimers and onControlPlaneClientError.
+ return activatedCpClients.entrySet().stream()
.filter(entry -> !entry.getValue().isEmpty()
&& cpc == entry.getValue().get(entry.getValue().size() - 1))
.map(Map.Entry::getKey)
- .collect(Collectors.toList());
-
- // Since this is usually used for contains, use a set when the list is large
- return (asList.size() < 100) ? asList : new HashSet<>(asList);
+ .collect(Collectors.toCollection(HashSet::new));
}