java-topology/defects/clickhouse-java/patch/clickhouse-java-0001-load-balancing-faulty-nodes-linked-list.patch
russell@unturf.com e9b981a309 clickhouse-java/freeswitch: CWE-407 findings
clickhouse-java-0001: ClickHouseLoadBalancingPolicy nodes/faultyNodes
LinkedList.contains O(N*F) per node selection — fix: LinkedHashSet O(1).
120x speedup at F=500 faulty nodes.

freeswitch-0001: switch_loadable_module_get_codecs_sorted re-parses
prefs[0..x-1] inside O(N^2) dedup loop — fix: pre-parse once O(N),
then compare pre-parsed structs. 13x speedup at N=50 (SWITCH_MAX_CODECS).
2026-03-30 09:03:28 -04:00

24 lines
1.1 KiB
Diff

# UNDF: UNDF-2026-000000745
# UNDF: (leave blank)
--- a/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseNodes.java
+++ b/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseNodes.java
@@ -324,10 +324,10 @@ public class ClickHouseNodes implements ClickHouseNodeManager {
* List of healthy nodes.
*/
- protected final LinkedList<ClickHouseNode> nodes;
+ protected final LinkedHashSet<ClickHouseNode> nodes;
/**
* List of faulty nodes.
*/
- protected final LinkedList<ClickHouseNode> faultyNodes;
+ protected final LinkedHashSet<ClickHouseNode> faultyNodes;
@@ -373,8 +373,8 @@ public class ClickHouseNodes implements ClickHouseNodeManager {
this.checking = new AtomicBoolean(false);
this.index = new AtomicInteger(0);
this.lock = new ReentrantReadWriteLock();
- this.nodes = new LinkedList<>(); // usually just healthy nodes
- this.faultyNodes = new LinkedList<>();
+ this.nodes = new LinkedHashSet<>(); // O(1) contains for load-balancing hot path
+ this.faultyNodes = new LinkedHashSet<>(); // O(1) contains for health check