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 ...
随机推荐
- CF 988C Equal Sums 思维 第九题 map
Equal Sums time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
- hadoop之数据倾斜
数据倾斜介绍 在做Shuffle阶段的优化过程中,遇到了数据倾斜的问题,造成了对一些情况下优化效果不明显.主要是因为在Job完成后的所得到的Counters是整个Job的总和,优化是基于这些Count ...
- 1 PY环境与变量
一 环境与文件形式 1.环境搭建http://jingyan.baidu.com/article/eae07827f7f2d01fec5485f7.html 2. python 则进入交互模式 ex ...
- 自定义Hive UDAF 实现相邻去重
内置的两个聚合函数(UDAF) collect_list():多行字符串拼接为一行collect_set():多行字符串拼接为一行并去重多行字符串拼接为一行并相邻去重UDAF:Concat() con ...
- ssh-agent代理的简单用法
前言 在ansible的官方文档中,提到了强烈推荐用ssh-agent来管理密钥 究竟ssh-agent是什么,它有什么用法呢,下面来一探究竟. ssh-agent是什么?用处是什么? ssh-age ...
- Git使用(一)安装配置过程-Win7
公司项目需要使用Git作为项目的代码库管理工具.正好借此机会写个安装过程 1.首先下载Git下载地址:https://git-scm.com/download/win 当前下载版本:Git-2.13. ...
- java读写文件IO
package Common.readFile; import Common.tool.User; import com.fasterxml.jackson.databind.ObjectMapper ...
- Salesforce LWC学习(七) Navigation & Toast
上一篇我们介绍了针对LWC中常用的LDS的适配的wire service以及@salesforce模块提供的相关的service,其实LWC中还提供其他的好用的service,比如针对导航相关的lig ...
- 实验吧CTF练习题---WEB---因缺思汀的绕过解析
实验吧web之因缺思汀的绕过 地址:http://www.shiyanbar.com/ctf/1940 flag值: 解题步骤: 1.点开题目,观察题意 2.通过观察题目要求,判断此道题还有代码审 ...
- js数组增删元素
操作数组的方法 push() 结尾添加 数组.push(元素) 参数 描述 newelement1 必需.要添加到数组的第一个元素. newelement2 可选.要添加到数组的第二个元素. newe ...