MongoDB connection drops - mongodb

The connection from applications in the Kubernetes cluster to the Mongo DB (Atlas) basically works. However, sometimes the connection drops and I can't figure out why. There are two different errors in my logs that seem to be related:
Timed out after 30000 ms while waiting for a server that matches WritableServerSelector. Client view of cluster state is {type=REPLICA_SET, servers=[{address=xxxxx-tedsb.gcp.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection timed out}}, {address=xxxxx-shard-00-01-tedsb.gcp.mongodb.net:27017, type=REPLICA_SET_SECONDARY, TagSet{[Tag{name='nodeType', value='ELECTABLE'}, Tag{name='provider', value='GCP'}, Tag{name='region', value='EUROPE_NORTH_1'}]}, roundTripTime=34.3 ms, state=CONNECTED}, {address=xxxxx.gcp.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection timed out}}]
and
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.connection.TlsChannelStreamFactoryFactory$TlsChannelStream.lambda$openAsync$0(TlsChannelStreamFactoryFactory.java:246)
at com.mongodb.connection.TlsChannelStreamFactoryFactory$SelectorMonitor.lambda$start$0(TlsChannelStreamFactoryFactory.java:141)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection timed out
at java.base/sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
at com.mongodb.connection.TlsChannelStreamFactoryFactory$TlsChannelStream.lambda$openAsync$0(TlsChannelStreamFactoryFactory.java:218)
... 2 more
I'm not hitting the limit of number of connections and the pod itself is also not under pressure (memory, cpu, disk space). Same goes for the JVM. I'm using the official drivers ("org.mongodb.scala" %% "mongo-scala-driver" % "4.1.0") and Mongo 4.2.8.
The configuration I'm using is pretty basic:
private val uri = configuration.get[String]("mongodb.uri")
private val clientSettings = MongoClientSettings
.builder()
.uuidRepresentation(UuidRepresentation.STANDARD)
.applyConnectionString(new ConnectionString(uri))
.codecRegistry(Registry)
.build()
val client = MongoClient(clientSettings)
I found this (issue)[https://jira.mongodb.org/browse/JAVA-3274] that got resolved in mongo-scala-driver: 4.1.0 and I was hoping that this would fix my issue, but it didn't.
Any idea what I could check next?

Apparently there is a connectivity issue between your pod and two of the three nodes of the replica set. Since the node that is visible is currently a secondary, the driver cannot satisfy the readPreference=primary that is set by default and therefore times out after a while.
I would review your firewall configuration, make sure your pod has access to all three nodes and not just one. Also, ensure that your pod's IP address is whitelisted in Atlas.

Related

Mongo time out error when trying to read data using connection uri

This is my connection URI
"mongodb+srv://myUserName:myPassWord#myHost/myDb?retryWrites=true&w=majority"
My user has readAnyDatabase role. But when I try to find a document I get this error.
Error printing return value (MongoTimeoutException) at com.mongodb.internal.connection.BaseCluster/createTimeoutException (BaseCluster.java:401).
Timed out after 30000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1#63d3bb68. Client view of cluster state is {type=REPLICA_SET,
servers=[{address=myDb-shard-00-00.qwert.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: Connect timed out}},
{address=myDb-shard-00-02.qwert.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: Connect timed out}},
{address=myDb-shard-00-01.qwert.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: Connect timed out}}]
If you see it's able to connect to the Mongo DB (I am infering this from the fact that it is able to discover all the nodes from myDb-shard-00-00 to myDb-shard-00-02), but gives this error when trying to read some data.
I have connected to other mongo dbs (different uri) with the same code and successfully read documents. So, I am guessing that there should be something wrong with my configuration? Or is it something else? What is the direction that I should be looking at to debug this?

connecting to local mongodb from drone.io

mongodb is running on my local machine and i want to connect this mongodb from drone.io. but i am getting error message as below
com.mongodb.com.mongodb.MongoTimeoutException:
com.mongodb.MongoTimeoutException: Timed out after 30000 ms while
waiting for a server that matches
ReadPreferenceServerSelector{readPreference=primary}. Client view of
cluster state is {type=UNKNOWN, servers=[{address=localhost:27017,
type=UNKNOWN, state=CONNECTING,
exception={com.mongodb.MongoSocketOpenException: Exception opening
socket}, caused by {java.net.ConnectException: Connection refused}}]
Can any one help on this how can i connect my local mongodb from drone.io

Kubernetes pod connection to MongoDB Atlas issues

I have two pods in my Kubernetes cluster - one is connecting just fine to my MongoDB Atlas cluster, the other is failing due to the following exception:
Caused by: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches WritableServerSelector.
Client view of cluster state is {type=REPLICA_SET, servers=[{address=MY_MONGO_SERVER1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}, {address=MY_MONGO_SERVER2:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}, {address=MY_MONGO_SERVER3:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}]
Now I'm not sure why one pod is able to connect, while the second one fails. We have another environment (production) that has similar configuration and all is fine with that environment's pods. Also, that environment runs on same Atlas cluster-sized DB, with similarly configured Kubernetes deployments.

Unable to connect to Mongo Using VertxMongo clinent

Hi enables ssl in mongo server and trying to connect from vertx MongoClient.
Step followed : "ssl":true in configuration and set System.setProperty("org.mongodb.async.type", "netty") before intializing the clinet. When I try running my vertx application i am getting following error. can some one please help?
com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=testssl#cv.com:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketWriteException: Exception sending message}, caused by {javax.net.ssl.SSLException: SSLEngine closed already}}]
at com.mongodb.connection.BaseCluster.createTimeoutException(BaseCluster.java:377)
at com.mongodb.connection.BaseCluster.handleServerSelectionRequest(BaseCluster.java:292)
at com.mongodb.connection.BaseCluster.access$800(BaseCluster.java:54)
at com.mongodb.connection.BaseCluster$WaitQueueHandler.run(BaseCluster.java:458)
at java.lang.Thread.run(Thread.java:745)

getting an error while connecting mongodb with replicaset-Bitnami

I have deployed bitnami MongoDB with replicaset on Azure and I haven't changed anything but when I try to connect MongoDB using connection string then I'm getting an error like `
Connection failed.
SERVER [xyz.southeastasia.cloudapp.azure.com:27017] (Type: UNKNOWN)
|_/ Connection error (MongoSocketReadTimeoutException): Timeout while receiving message
|____/ I/O error: Read timed out
Details:
Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=xyz.southeastasia.cloudapp.azure.com:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadTimeoutException: Timeout while receiving message}, caused by {java.net.SocketTimeoutException: Read timed out}}]
I have running bitnami mongodb with replicaset on azure which was created one month back that time i haven't faced this issue.
It looks to me that the address may have changed. I advise you to confirm that xyz.southeastasia.cloudapp.azure.com still points to the same IP address you want to connect. Also check that there are no firewall rules blocking the traffic.