【问题标题】:Mongodb Atlas "Got Socket exception on Connection To Cluster"Mongodb Atlas“连接到集群时出现套接字异常”
【发布时间】:2020-11-01 20:44:39
【问题描述】:

我正在使用 Java & Springboot 和 MongoDB Atlas 并创建了一个响应许多对象的 CURD 的数据库

当我在 uploadingImage 上发帖时,我收到了这个错误Got Socket exception on Connection [connectionId{localValue:4, serverValue:114406}] to cluster0-shard-00-02.1c6kg.mongodb.net:27017

但是,当我调用其他对象的 CRUD 时,它工作得很好。我不为什么它会引发这个异常。顺便说一句,当没有连接到 MongoDB Atlas 时,我对所有对象的所有 CRUD 操作在 localhost 上运行良好,这意味着我的 ImageDAO 应该没问题,我只是使用了mongoTemplate.insert(Image)

我在网上搜索,他们说可能是 Atlas 的 IP 白名单,所以我将我的集群设置为对任何 IP 地址开放。

我还在我的 .properties 文件中设置了我的超时和套接字配置: spring.data.mongodb.uri=mongodb+srv://username:password@cluster0.1c6kg.mongodb.net/database?retryWrites=true&w=majority&keepAlive=true&pooSize=30&autoReconnect=true&socketTimeoutMS=361000000&connectTimeoutMS=3600000

还是不行,我觉得肯定是socket超时的问题,但是不知道还有哪里可以配置

【问题讨论】:

  • mongodb-atlas-search是不是合适的tag建森?可以分享一下查询吗?

标签: java mongodb spring-boot mongodb-atlas mongodb-atlas-search


【解决方案1】:

错误日志在这里: 2020-11-01 12:25:34.275 WARN 20242 --- [nio-8088-exec-1] org.mongodb.driver.connection:在连接 [connectionId{localValue:4, serverValue:114406}] 上出现套接字异常cluster0-shard-00-02.1c6kg.mongodb.net:27017。与 cluster0-shard-00-02.1c6kg.mongodb.net:27017 的所有连接都将关闭。 2020-11-01 12:25:34.283 INFO 20242 --- [nio-8088-exec-1] org.mongodb.driver.connection:关闭连接 [connectionId{localValue:4, serverValue:114406}] 到 cluster0-shard -00-02.1c6kg.mongodb.net:27017 因为此连接引发了套接字异常。 2020-11-01 12:25:34.295 INFO 20242 --- [nio-8088-exec-1] org.mongodb.driver.cluster:WritableServerSelector 从集群描述 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=46076648, 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='AWS'}, Tag{name= '区域',值='US_WEST_2'},标签{name='workloadType',值='OPERATIONAL'}] },electionId=null,setVersion=1,lastWriteDate=Sun Nov 01 12:25:29 PST 2020,lastUpdateTimeNanos=104428017411386},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=41202444,setName='atlas-d9ovwb-shard-0',canonicalAddress=cluster0-shard-00-01.1c6kg.mongodb.net:27017,hosts=[cluster0-shard-00-00.1c6kg.mongodb。净:27017,cluster0-shard-00-01.1c6kg.mongodb.net:27017,cluster0-shard-00-02.1c6kg.mongodb.net:27017],被动= [],仲裁= [],主要='cluster0- shard-00-02.1c6kg.mongodb.net:27017',tagSet=TagSet{[Tag{name='nodeType',value='ELECTABLE'},Tag{name='provider',value='AWS'},Tag {name='region',value='US_WEST_2'},Tag{name='workloadType',value='OPERATIONAL'}]},electionId=null,setVersion =1,lastWriteDate=2020 年 11 月 1 日星期日 12:25:29 PST,lastUpdateTimeNanos=104428010234368}]}。在超时前等待 30000 毫秒 2020-11-01 12:25:34.316 INFO 20242 --- [ngodb.net:27017] org.mongodb.driver.cluster:发现副本集主 cluster0-shard-00-02.1c6kg.mongodb.net:27017 2020-11-01 12:25:34.612 INFO 20242 --- [nio-8088-exec-1] org.mongodb.driver.connection:打开连接 [connectionId{localValue:5, serverValue:108547}] 到 cluster0-shard -00-02.1c6kg.mongodb.net:27017 2020-11-01 12:25:34.838 WARN 20242 --- [nio-8088-exec-1] org.mongodb.driver.connection:连接 [connectionId{localValue:5, serverValue:108547}] 时出现套接字异常cluster0-shard-00-02.1c6kg.mongodb.net:27017。与 cluster0-shard-00-02.1c6kg.mongodb.net:27017 的所有连接都将关闭。 2020-11-01 12:25:34.838 INFO 20242 --- [nio-8088-exec-1] org.mongodb.driver.connection:关闭连接 [connectionId{localValue:5, serverValue:108547}] 到 cluster0-shard -00-02.1c6kg.mongodb.net:27017 因为此连接引发了套接字异常。 2020-11-01 12:25:34.876 INFO 20242 --- [ngodb.net:27017] org.mongodb.driver.cluster:发现副本集主 cluster0-shard-00-02.1c6kg.mongodb.net:27017 2020-11-01 12:25:34.878 错误 20242 --- [nio-8088-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]:Servlet.service() 用于 servlet [dispatcherServlet] path [] 抛出异常 [请求处理失败;嵌套异常是 org.springframework.data.mongodb.UncategorizedMongoDbException: 异常发送消息;嵌套异常是 com.mongodb.MongoSocketWriteException: Exception sent message] with root cause

【讨论】:

    猜你喜欢
    • 2018-03-05
    • 1970-01-01
    • 2020-01-15
    • 2017-12-12
    • 1970-01-01
    • 2019-06-10
    • 2021-04-29
    • 2022-06-13
    • 2019-08-02
    相关资源
    最近更新 更多