Skip to content

Commit a6e3ce4

Browse files
committed
[JAVA-252]: prevent removal of all nodes if all nodes update fail
1 parent 6125995 commit a6e3ce4

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/main/com/mongodb/ReplicaSetStatus.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,14 @@ synchronized void updateAll(){
285285
n.update(seenNodes);
286286
}
287287

288-
// remove unused hosts
289-
Iterator<Node> it = _all.iterator();
290-
while (it.hasNext()) {
291-
if (!seenNodes.contains(it.next()))
292-
it.remove();
288+
if (!seenNodes.isEmpty()) {
289+
// not empty, means that at least 1 server gave node list
290+
// remove unused hosts
291+
Iterator<Node> it = _all.iterator();
292+
while (it.hasNext()) {
293+
if (!seenNodes.contains(it.next()))
294+
it.remove();
295+
}
293296
}
294297
}
295298

0 commit comments

Comments
 (0)