Skip to content

Commit a3d6b8e

Browse files
committed
JAVA-2074: Fix race condition in MultiServerCluster checking whether the instance is closed.
1 parent 59f0ddf commit a3d6b8e

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/main/com/mongodb/MultiServerCluster.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ protected void connect() {
8888

8989
@Override
9090
public void close() {
91-
if (!isClosed()) {
92-
synchronized (this) {
91+
synchronized (this) {
92+
if (!isClosed()) {
9393
for (ServerTuple serverTuple : addressToServerTupleMap.values()) {
9494
serverTuple.server.close();
9595
}
96+
super.close();
9697
}
97-
super.close();
9898
}
9999
}
100100

@@ -117,12 +117,12 @@ public void stateChanged(final ChangeEvent<ServerDescription> event) {
117117
}
118118

119119
private void onChange(final ChangeEvent<ServerDescription> event) {
120-
if (isClosed()) {
121-
return;
122-
}
123-
124120
boolean shouldUpdateDescription = true;
125121
synchronized (this) {
122+
if (isClosed()) {
123+
return;
124+
}
125+
126126
ServerDescription newDescription = event.getNewValue();
127127

128128
LOGGER.fine(format("Handling description changed event for server %s with description %s",

0 commit comments

Comments
 (0)