For a few days now, I can’t connect to any of my MongoDB Databases that are hosted by Altas. I’m always getting a MongoTimeoutException
Exception in thread "Thread-9" com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1@3691e69a. Client view of cluster state is {type=REPLICA_SET, servers=[{address=statify-shard-00-02.st9vh.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketWriteException: Exception sending message}, caused by {javax.net.ssl.SSLHandshakeException: extension (5) should not be presented in certificate_request}}, {address=statify-shard-00-00.st9vh.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketWriteException: Exception sending message}, caused by {javax.net.ssl.SSLHandshakeException: extension (5) should not be presented in certificate_request}}, {address=statify-shard-00-01.st9vh.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketWriteException: Exception sending message}, caused by {javax.net.ssl.SSLHandshakeException: extension (5) should not be presented in certificate_request}}] at com.mongodb.internal.connection.BaseCluster.createTimeoutException(BaseCluster.java:407) at com.mongodb.internal.connection.BaseCluster.selectServer(BaseCluster.java:118) at com.mongodb.internal.connection.AbstractMultiServerCluster.selectServer(AbstractMultiServerCluster.java:52) at com.mongodb.client.internal.MongoClientDelegate.getConnectedClusterDescription(MongoClientDelegate.java:137) at com.mongodb.client.internal.MongoClientDelegate.createClientSession(MongoClientDelegate.java:95) at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.getClientSession(MongoClientDelegate.java:266) at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:170) at com.mongodb.client.internal.MongoIterableImpl.execute(MongoIterableImpl.java:135) at com.mongodb.client.internal.MongoIterableImpl.iterator(MongoIterableImpl.java:92) at de.visionvenue.statify.main.Main.lambda$3(Main.java:235) at java.base/java.lang.Thread.run(Thread.java:834)
Line 233-235 in Main
MongoCollection<Document> collection = MongoDBHandler.getDatabase().getCollection("statistics"); FindIterable<Document> iterDoc = collection.find(); Iterator<Document> it = iterDoc.iterator();
Here is the class where I connect to the Database
public class MongoDBHandler { static MongoDatabase db; public static void connect() { try { ConnectionString connString = new ConnectionString( "mongodb+srv://[USERNAME]:[PASSWORD]@statify.st9vh.mongodb.net/[DATABASE]?retryWrites=true&w=majority"); MongoClientSettings settings = MongoClientSettings.builder().applyConnectionString(connString) .retryWrites(true).build(); MongoClient mongoClient = MongoClients.create(settings); MongoDatabase database = mongoClient.getDatabase("Database"); System.out.println("Connected to database"); db = database; } catch (Exception ex) { String error = ex.toString() + "n"; for (int i = 0; i < ex.getStackTrace().length; i++) { error = error + ex.getStackTrace()[i].toString() + "n"; } ReportManager.createInstantReport("MongoDB Connection", error); } } public static MongoDatabase getDatabase() { return db; } }
I replaced the user, password and database for this post.
I already checked everything twice. The IP is whitelisted, the connection server is the same, username and password are correct. This code worked fine, but suddenly broke. I haven’t changed anything releated to the Database that could cause this issue.
Advertisement
Answer
I just contacted the MongoDB Support. They told me that this is a current bug in TLS 1.3. I changed the Java Version to 8 and it worked
The official Bug Report can be found here: https://bugs.openjdk.java.net/browse/JDK-8236039