Timed out after 30000 ms while waiting to connect
今天使用mongo-java-drive写连接mongo的客户端,着实被上面那个错坑了一把。回顾一下解决过程:
报错:
com.mongodb.MongoTimeoutException: Timed out after ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketWriteException: Exception sending message}, caused by {javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake}, caused by {java.io.EOFException: SSL peer shut down incorrectly}}]
at com.mongodb.connection.BaseCluster.getDescription(BaseCluster.java:)
at com.mongodb.client.internal.MongoClientDelegate.getConnectedClusterDescription(MongoClientDelegate.java:)
at com.mongodb.client.internal.MongoClientDelegate.createClientSession(MongoClientDelegate.java:)
at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.getClientSession(MongoClientDelegate.java:)
at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:)
at com.mongodb.client.internal.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:)
at com.mongodb.client.internal.MongoCollectionImpl.executeInsertOne(MongoCollectionImpl.java:)
at com.mongodb.client.internal.MongoCollectionImpl.insertOne(MongoCollectionImpl.java:)
at com.mongodb.client.internal.MongoCollectionImpl.insertOne(MongoCollectionImpl.java:)
at com.czb.chargepile.core.MongeTemplate.insert(MongeTemplate.java:)
at com.czb.chargepile.manage.X01Manager.insert(X01Manager.java:)
at manage.X01ManagerTest.main(X01ManagerTest.java:)
分析:mongodb数据库连接超时,也就是客户端连不上mongo
代码:
MongoCredential credential = MongoCredential.createCredential(user, databaseName, password); mongoClient = MongoClients.create( MongoClientSettings.builder() .applyToSslSettings(builder -> builder.enabled(true)) .applyToClusterSettings(builder -> builder.hosts(Arrays.asList(new ServerAddress("localhost", 27017)))) .credential(credential) .build()); MongoDatabase database = mongoClient.getDatabase(databaseName);
解决:
1、看到错误,首先想到的是用户名密码不对,为了确保密码无误,重新设置了mongo的密码,然而并未好使
2、检查用户所属数据库是否正确,经过检查,发现完全匹配
检查mongo-java-drive版本是否和mongo版本匹配,发现完全匹配
4、最后开始怀疑上面的代码有问题,找官方文档https://mongodb.github.io/mongo-java-driver/3.8/driver/tutorials/authentication/,从这里找到了新的写法,先无脑拷贝,然后运行,发现这里写法是成功的,与自己的代码对比,发现我的代码多了一行
.applyToSslSettings(builder -> builder.enabled(true))
回到我代码,去掉,发现成功了。又回去看官方文档,找到端倪

如果使用那个选项,传输过程会使用TLS/SSL对传输层进行加密,但是我的mongo服务是没有对应设置的,所以导致连接不上。
Timed out after 30000 ms while waiting to connect的更多相关文章
- (node:7584) UnhandledPromiseRejectionWarning: MongooseTimeoutError: Server selection timed out after 30000 ms
记录一次学习node.js犯的低级错误 这里遇到一个这样的问题 express连接mongoose时报错(node:7584) UnhandledPromiseRejectionWarning: Mo ...
- mongo连接不上Timed out after 30000
本地连接mongo报错,错误代码为: Caused by: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while wait ...
- 【异常】Reason: Executor heartbeat timed out after 140927 ms
1 详细异常 ERROR scheduler.JobScheduler: Error running job streaming job ms. org.apache.spark.SparkExcep ...
- php Connection timed out after 30000 milliseconds
function HttpRequest($url, $params, $method = 'GET', $header = array(), $bEncode = true){ $opts = ar ...
- java连接mongodb的一个奇葩问题及奇葩解决方式
昨天在eclipse中编写代码,本来连接mongodb进行各项操作都是正常的,但是有一会儿突然之间就没法连接了,还一直抱错,错误如下: 信息: Cluster created with setting ...
- mongodb单机搭建
参考网站:http://www.runoob.com/mongodb/mongodb-linux-install.html 1.下载 https://www.mongodb.com/download- ...
- Android跟蓝牙耳机建立连接有两种方式
Android 跟蓝牙耳机建立连接有两种方式. 1. Android 主动跟蓝牙耳机连BluetoothSettings 中和蓝牙耳机配对上之后, BluetoothHeadsetService 会收 ...
- Android 蓝牙( Bluetooth)耳机连接分析及实现
Android 实现了对Headset 和Handsfree 两种profile 的支持.其实现核心是BluetoothHeadsetService,在PhoneApp 创建的时候会启动它. if ( ...
- Mongo集群Java连接时UnknownHostException错误
今天在 Java 连接 Mongo 集群时报了一个超时的错误,但是在本地客户端连接单节点的时候却能连上,具体报的错误如下: Caused by: com.mongodb.MongoTimeoutExc ...
随机推荐
- poj 2649 Factovisors 对n!进行因数分解
Factovisors Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4431 Accepted: 1086 Descr ...
- Kafka中的ISR、AR又代表什么?ISR的伸缩又指什么?
相信大家已经对 kafka 的基本概念已经有一定的了解了,下面直接来分析一下 ISR 和 AR 的概念. ISR and AR 简单来说,分区中的所有副本统称为 AR (Assigned Replic ...
- 实现 Java 本地缓存,该从这几点开始
缓存,我相信大家对它一定不陌生,在项目中,缓存肯定是必不可少的.市面上有非常多的缓存工具,比如 Redis.Guava Cache 或者 EHcache.对于这些工具,我想大家肯定都非常熟悉,所以今天 ...
- 适合C++のOIer平日写题的开场模板
上面的#define还是较充足的,快读模板也有,freopen也提前打好了,比较适合OIer(C++)平时刷题和考试的开场. (纯原版仅供SJZEZのORZ队&AFO队使用) (您老把开头的注 ...
- 关于JQuery.form.js异步上传文件点滴
好久没动代码了,前几天朋友委托我帮忙给做几个页面,其中有个注册带图片上传的页面.已之前的经验应该很快就能搞定,没想到的是搞了前后近一天时间.下面就说说异步上传的重要几个点,希望自己下次遇到此类问题的时 ...
- java中的equals方法与"=="运算符解说
在编程的时候,我们可能经常会用到equals方法,那么这个equals方法和运算符“==”有什么样的区别? public class equal { /** * @param args */ publ ...
- CCPC桂林
在得知我们队伍前往桂林参加CPPC区域赛后,我是非常激动的,因为我们网络赛并没有得到名额,如果不是新都赠予我们名额,我们都没有出去打比赛的机会,同时,我们也不想浪费这个名额,我们也想打出成绩来,于是我 ...
- 自定义JDBC工具类
因为数据库的连接代码都是固定的,为了将减少重复的代码的书写,可以将这些代码封装为一个工具类,获取数据库的连接对象. import java.sql.Connection; import java.sq ...
- charles 禁用缓存
本文参考:charles 禁用缓存 No caching Settings/无缓存工具的用法 弹窗面板上一句话概括了他的工作原理:通过修改请求和响应头来防止缓存; 无缓存工具 无缓存工具阻止客户端应用 ...
- [Leetcode] 第307题 区域和检索-数组可修改
参考博客:(LeetCode 307) Range Sum Query - Mutable(Segment Tree) 一.题目描述 给定一个整数数组 nums,求出数组从索引 i 到 j (i ...