Skip to content

Commit 15ad618

Browse files
committed
JAVA-2074: Fix race condition in MultiServerCluster checking whether the instance is closed.
1 parent 7d51087 commit 15ad618

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

driver-core/src/main/com/mongodb/connection/MultiServerCluster.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ protected void connect() {
9393

9494
@Override
9595
public void close() {
96-
if (!isClosed()) {
97-
synchronized (this) {
96+
synchronized (this) {
97+
if (!isClosed()) {
9898
for (final ServerTuple serverTuple : addressToServerTupleMap.values()) {
9999
serverTuple.server.close();
100100
}
@@ -123,12 +123,12 @@ public void stateChanged(final ChangeEvent<ServerDescription> event) {
123123
}
124124

125125
private void onChange(final ChangeEvent<ServerDescription> event) {
126-
if (isClosed()) {
127-
return;
128-
}
129-
130126
boolean shouldUpdateDescription = true;
131127
synchronized (this) {
128+
if (isClosed()) {
129+
return;
130+
}
131+
132132
ServerDescription newDescription = event.getNewValue();
133133

134134
if (LOGGER.isTraceEnabled()) {

0 commit comments

Comments
 (0)