Today, a timeout error was reported when connecting to the Mongo cluster in Java, but it was able to connect when the local client was connected to a single node. The specific error reported is as follows:
Caused by: com.mongodb.MongoTimeoutException:
Timed out after 60000 ms while waiting for a server that matches
{serverSelectors=[ReadPreferenceServerSelector{readPreference=primaryPreferred}, LatencyMinimizingServerSelector{acceptableLatencyDifference=15 ms}]}.
Client view of cluster state is {type=ReplicaSet, servers=[{address=mongo.50:27017, type=Unknown,state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket},
caused by {java.net.UnknownHostException: mongo.50}},
{address=mongo.66:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket},
caused by {java.net.UnknownHostException: mongo.66}},
{address=mongo.67:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused
by {java.net.UnknownHostException: mongo.67}}]
I checked the IP address in the configuration file and there is no problem, but why does the error that mongo.50, mongo.66 and mongo.67 can’t resolve the three addresses appear in the error report? How did these three addresses come from? The Mongo cluster consists of 3 machines, and the last IPs are 50, 66, and 67 respectively. I guess it might be a problem with the cluster configuration.
There is a similar question on StackOverflow: (https://stackoverflow.com/questions/27607773/com-mongodb-mongotimeoutexception-when-using-mongoclient-with-list-serveraddress)
In fact, because of Mongo’s replica set method, the client decides which Mongo server to connect to. Each Mongo service listens to each other. If the main service is found to be down, it will elect a new master. The client will be notified when the new master is confirmed. The domain name is used when creating the replica set, so the primary address obtained by the client is also the domain name.
Therefore, the address configured in the mongo.50 cluster configured by the Java client cannot be resolved.
Then you only need to do one more step below to configure the hosts file of the machine. Corresponding to the corresponding IP and mongo.50 address can be resolved.
Or remove?replicaSet=rs0,The following is a summary of the main node, i.e., only the master node is connected, not the replica.
Read More:
- How to Solve kubelet starts error (k8s Cluster Restarted)
- How to Solve Redis Cluster Build Error
- How to Solve Docker Error: elasticsearch exception: type=cluster_block_exception, reason=blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];
- How to Solve Redis Cluster Error: (Error) Moved
- [Solved] dbeaver Connect clickhouse Error: Unexpected driver error occurred while connecting to the database
- [Solved] lightdb oracle_fdw Error: ERROR: error connecting to Oracle: OCIEnvCreate failed to create environment handle
- [Solved] elasticsearch Error: Failed: 1: this action would add [6] total shards, but this cluster currently has [2
- [Solved] K8s cluster build error: error: kubectl get csr No resources found.
- [Solved] Android8.1 Compile Error: SSL error when connecting to the Jack server
- K8s cluster initialization error: Port 6443 is in use [Solved]
- postman Error:There was an error connecting to XXXX
- Redis Cluster Error: (error) CLUSTERDOWN Hash slot not served
- [Solved] java.lang.reflect.InaccessibleObjectException: Unable to make protected java.net.http.HttpRequest()…
- [Solved] Nacos Cluster startup error: error=‘Cannot allocate memory‘ (errno=12)
- Win10 remote connection submits error by using cluster: Batch: error: batch script contains DOS line breaks (\R\n) sbatch: error
- [Solved] Response Export error on submit request on future invoke, java.lang.OutOfMemoryError: Java heap space
- Hive ERROR Failed with exception java.io.IOException:java.lang.IllegalArgumentException
- [Solved] Failed to bind properties under ‘spring.datasource.type‘ to java.lang.Class<javax.sql.DataSource>
- [Solved] IDEA Error: java: Compilation failed: internal java compiler error
- [Solved] Android Error: java.lang.IllegalStateException: Not allowed to start service Intent