From ca13ea6a2a4f17c2be43cc0fb4b4eb8baa2da6df Mon Sep 17 00:00:00 2001 From: Roger3581321 Date: Mon, 7 Feb 2022 10:38:23 +0800 Subject: [PATCH] Use CopyOnWriteArraySet for ConnectionGroup#connectionSet to avoid iterator fast-fail (#2559) --- .../sentinel/cluster/server/connection/ConnectionGroup.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionGroup.java b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionGroup.java index 9a3d53cd28..4fb3376084 100644 --- a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionGroup.java +++ b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionGroup.java @@ -19,6 +19,7 @@ import java.util.HashSet; import java.util.Set; import java.util.concurrent.ConcurrentSkipListSet; +import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.atomic.AtomicInteger; import com.alibaba.csp.sentinel.cluster.server.ServerConstants; @@ -34,7 +35,7 @@ public class ConnectionGroup { private final String namespace; - private final Set connectionSet = Collections.synchronizedSet(new HashSet()); + private final Set connectionSet = new CopyOnWriteArraySet<>(); private final AtomicInteger connectedCount = new AtomicInteger(); public ConnectionGroup(String namespace) {