From 04a1d065dd54917ec26c4c78095417df3e7085c7 Mon Sep 17 00:00:00 2001 From: haifeng Date: Sun, 26 Apr 2020 10:58:27 +0800 Subject: [PATCH] Fix the bug of misplaced locks in ContextUtil and ClusterNode (#1429) - which may lead to IllegalMonitorStateException in unlock() when unchecked error occurs during lock() --- .../main/java/com/alibaba/csp/sentinel/context/ContextUtil.java | 2 +- .../main/java/com/alibaba/csp/sentinel/node/ClusterNode.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/context/ContextUtil.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/context/ContextUtil.java index 9af5f762..5e0ae023 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/context/ContextUtil.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/context/ContextUtil.java @@ -127,8 +127,8 @@ public class ContextUtil { setNullContext(); return NULL_CONTEXT; } else { + LOCK.lock(); try { - LOCK.lock(); node = contextNameNodeMap.get(name); if (node == null) { if (contextNameNodeMap.size() > Constants.MAX_CONTEXT_NAME_SIZE) { diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/ClusterNode.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/ClusterNode.java index 6f5f4ef4..0e085087 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/ClusterNode.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/ClusterNode.java @@ -101,8 +101,8 @@ public class ClusterNode extends StatisticNode { public Node getOrCreateOriginNode(String origin) { StatisticNode statisticNode = originCountMap.get(origin); if (statisticNode == null) { + lock.lock(); try { - lock.lock(); statisticNode = originCountMap.get(origin); if (statisticNode == null) { // The node is absent, create a new node for the origin.