Authentication failures against a mongos causes connection leaks after running MongoClient.close
@@ -141,7 +141,9 @@ public class ServerSessionPool {
return;
}
- Connection connection = cluster.selectServer(new ServerSelector() {
+ Connection connection = null;
+ try {
+ connection = cluster.selectServer(new ServerSelector() {
@Override
public List<ServerDescription> select(final ClusterDescription clusterDescription) {
for (ServerDescription cur : clusterDescription.getServerDescriptions()) {
@@ -152,16 +154,18 @@ public class ServerSessionPool {
return Collections.emptyList();
}
}).getConnection();
- try {
+
connection.command("admin",
new BsonDocument("endSessions", new BsonArray(identifiers)), new NoOpFieldNameValidator(),
ReadPreference.primaryPreferred(), new BsonDocumentCodec(), NoOpSessionContext.INSTANCE);
} catch (MongoException e) {
// ignore exceptions
} finally {
+ if (connection != null) {
connection.release();
}
}
+ }
private boolean shouldPrune(final ServerSessionImpl serverSession) {
Integer logicalSessionTimeoutMinutes = cluster.getCurrentDescription().getLogicalSessionTimeoutMinutes();
