MongoTimeoutException on Mongo 4.0 in Atlas with AWS EC2 using 4.1.1 mongo client

JDK: openjdk version “11.0.10” 2021-01-19
Mongoclient version: 4.1.1
Mongo database used in Atlas: 4.0.23
Deployed in: AWS

Please help in understanding what is causing the issue and resolving it.
Below is the exception seen in log as soon as the java application starts:

com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1@4f3e65f4. Client view of cluster state is {type=REPLICA_SET, servers=[{address=peeringvpc-shard-00-01.hbtm8.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}, {address=peeringvpc-shard-00-02.hbtm8.mongodb.net:27017,.....exception={`com.mongodb.MongoSocketOpenException: Exception opening socket`}, caused by {java.net.SocketTimeoutException: connect timed out}}]
	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)

This is resolved.
The route tables: Had to use route table with the proper subnet associated, not the one with nat.
The security groups: Had to update outbound rules with CIDR of atlas cluster.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.