Jiansen Huang
Jiansen Huang

Reputation: 49

MongoDB Atlas "MongoSocketException Exception sending message"

I got this problem when trying to upload an Image to the Atlas database with SpringBoot. When Ido the test on the local MongoDB database, it works well.

Also My project connected to Atlas well because I can use another api to upload "logo" image, but for my "Image" api, it not working, it prints this:

2020-11-01 18:04:17.095  WARN 27452 --- [nio-8088-exec-2] org.mongodb.driver.connection            : Got socket exception on connection [connectionId{localValue:4, serverValue:37526}] to cluster0-shard-00-02.1c6kg.mongodb.net:27017. All connections to cluster0-shard-00-02.1c6kg.mongodb.net:27017 will be closed.
2020-11-01 18:04:17.103  INFO 27452 --- [nio-8088-exec-2] org.mongodb.driver.connection            : Closed connection [connectionId{localValue:4, serverValue:37526}] to cluster0-shard-00-02.1c6kg.mongodb.net:27017 because there was a socket exception raised by this connection.
2020-11-01 18:04:17.104  INFO 27452 --- [nio-8088-exec-2] org.mongodb.driver.cluster               : No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=MULTIPLE, serverDescriptions=[ServerDescription{address=cluster0-shard-00-00.1c6kg.mongodb.net:27017, type=REPLICA_SET_SECONDARY, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=8, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=67785768, setName='atlas-d9ovwb-shard-0', canonicalAddress=cluster0-shard-00-00.1c6kg.mongodb.net:27017, hosts=[cluster0-shard-00-00.1c6kg.mongodb.net:27017, cluster0-shard-00-01.1c6kg.mongodb.net:27017, cluster0-shard-00-02.1c6kg.mongodb.net:27017], passives=[], arbiters=[], primary='cluster0-shard-00-02.1c6kg.mongodb.net:27017', tagSet=TagSet{[Tag{name='nodeType', value='ELECTABLE'}, Tag{name='provider', value='GCP'}, Tag{name='region', value='CENTRAL_US'}, Tag{name='workloadType', value='OPERATIONAL'}]}, electionId=null, setVersion=1, lastWriteDate=Sun Nov 01 18:04:13 PST 2020, lastUpdateTimeNanos=124567789557591}, ServerDescription{address=cluster0-shard-00-02.1c6kg.mongodb.net:27017, type=UNKNOWN, state=CONNECTING}, ServerDescription{address=cluster0-shard-00-01.1c6kg.mongodb.net:27017, type=REPLICA_SET_SECONDARY, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=8, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=70453359, setName='atlas-d9ovwb-shard-0', canonicalAddress=cluster0-shard-00-01.1c6kg.mongodb.net:27017, hosts=[cluster0-shard-00-00.1c6kg.mongodb.net:27017, cluster0-shard-00-01.1c6kg.mongodb.net:27017, cluster0-shard-00-02.1c6kg.mongodb.net:27017], passives=[], arbiters=[], primary='cluster0-shard-00-02.1c6kg.mongodb.net:27017', tagSet=TagSet{[Tag{name='nodeType', value='ELECTABLE'}, Tag{name='provider', value='GCP'}, Tag{name='region', value='CENTRAL_US'}, Tag{name='workloadType', value='OPERATIONAL'}]}, electionId=null, setVersion=1, lastWriteDate=Sun Nov 01 18:04:13 PST 2020, lastUpdateTimeNanos=124567793068830}]}. Waiting for 30000 ms before timing out
2020-11-01 18:04:17.273  INFO 27452 --- [ngodb.net:27017] org.mongodb.driver.cluster               : Discovered replica set primary cluster0-shard-00-02.1c6kg.mongodb.net:27017
2020-11-01 18:04:18.497  INFO 27452 --- [nio-8088-exec-2] org.mongodb.driver.connection            : Opened connection [connectionId{localValue:5, serverValue:41707}] to cluster0-shard-00-02.1c6kg.mongodb.net:27017
2020-11-01 18:04:19.725  WARN 27452 --- [nio-8088-exec-2] org.mongodb.driver.connection            : Got socket exception on connection [connectionId{localValue:5, serverValue:41707}] to cluster0-shard-00-02.1c6kg.mongodb.net:27017. All connections to cluster0-shard-00-02.1c6kg.mongodb.net:27017 will be closed.
2020-11-01 18:04:19.726  INFO 27452 --- [nio-8088-exec-2] org.mongodb.driver.connection            : Closed connection [connectionId{localValue:5, serverValue:41707}] to cluster0-shard-00-02.1c6kg.mongodb.net:27017 because there was a socket exception raised by this connection.

This is really wired, why I got this socket exception? I also set the socket-timeout to a large number

Here is my MongoDB configuration in the application.properties file: spring.data.mongodb.uri=mongodb+srv://admin:[email protected]/database-name?retryWrites=true&w=majority&connectTimeoutMS=12000&socketTimeoutMS=12000&keepAlive=true

I also check my dependencies, I have:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongo-java-driver</artifactId>
            <version>3.12.7</version>
        </dependency>

It's really frustrating, trying to solve this for few hours already. Is there anyway I can configure the Cluster-Shards on Atlas??

Thanks if someone knowing this problem

Upvotes: 1

Views: 2984

Answers (1)

Jiansen Huang
Jiansen Huang

Reputation: 49

The problem solved, it caused by the Java-Driver version of MongoDB. I was using Java 11 to compile my project, after I changed my Java to 14, problem solved

Upvotes: 1

Related Questions