Skip to content

Commit 306ba28

Browse files
kutzisazzad16
authored andcommitted
Protect rediscovering with double-checked locking (#1856)
#1854
1 parent 53194dd commit 306ba28

1 file changed

Lines changed: 25 additions & 20 deletions

File tree

src/main/java/redis/clients/jedis/JedisClusterInfoCache.java

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,33 +85,38 @@ public void renewClusterSlots(Jedis jedis) {
8585
if (!rediscovering) {
8686
try {
8787
w.lock();
88-
rediscovering = true;
88+
if (!rediscovering) {
89+
rediscovering = true;
8990

90-
if (jedis != null) {
9191
try {
92-
discoverClusterSlots(jedis);
93-
return;
94-
} catch (JedisException e) {
95-
//try nodes from all pools
96-
}
97-
}
92+
if (jedis != null) {
93+
try {
94+
discoverClusterSlots(jedis);
95+
return;
96+
} catch (JedisException e) {
97+
//try nodes from all pools
98+
}
99+
}
98100

99-
for (JedisPool jp : getShuffledNodesPool()) {
100-
Jedis j = null;
101-
try {
102-
j = jp.getResource();
103-
discoverClusterSlots(j);
104-
return;
105-
} catch (JedisConnectionException e) {
106-
// try next nodes
107-
} finally {
108-
if (j != null) {
109-
j.close();
101+
for (JedisPool jp : getShuffledNodesPool()) {
102+
Jedis j = null;
103+
try {
104+
j = jp.getResource();
105+
discoverClusterSlots(j);
106+
return;
107+
} catch (JedisConnectionException e) {
108+
// try next nodes
109+
} finally {
110+
if (j != null) {
111+
j.close();
112+
}
113+
}
110114
}
115+
} finally {
116+
rediscovering = false;
111117
}
112118
}
113119
} finally {
114-
rediscovering = false;
115120
w.unlock();
116121
}
117122
}

0 commit comments

Comments
 (0)