mongo集群Timeout问题

项目场景:

项目场景:springboot 项目连接阿里云 mongo。

问题描述:

再启动项目和查询mongo过程中报错:

No server chosen by ReadPreferenceServerSelector{readPreference=primary} from cluster description C
lusterDescription{type=UNKNOWN, connectionMode=MULTIPLE, serverDescriptions=[ServerDescription{address=xxx:3717, type=UNKNOWN, state=CONNECTING, excepti
on={com.mongodb.MongoSocketReadException: Prematurely reached end of stream}}, ServerDescription{address=xxx:3717, type=UNKNOWN, state=CONNECTING, excep
tion={com.mongodb.MongoSocketReadException: Prematurely reached end of stream}}]}. Waiting for 30000 ms before timing out
[2020-10-22 09:09:01.844][ERROR][unknown_8ea74c3c095b4c689a1b989f25fc6d9f][c.o.o.c.c.CRBDataQueryController]- userMobileList error 2348162338435 null 499611240792850432
org.springframework.dao.DataAccessResourceFailureException: 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=xxx:3717, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadException: Prematurely reached end of stream}}, {address=xxx:3717, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadException: Prematurely reached end of stream}}]; nested exception is 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=xxx:3717, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadException: Prematurely reached end of stream}}, {address=xxx:3717, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadException: Prematurely reached end of stream}}]

解决方案:

首先报错信息是非常重要的,不要视而不见

Caused by: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}.

刚开始根据这关键字去查资料,网上的解决方案以下几类:

  1. 设置timeout maxIdleTimeMS=3000
  2. mongo java 驱动版本问题
  3. 用户名密码、地址、端口等问题
  4. 防火墙问题

然后一个个分析,
对于1. 确实认为大概率是这方面问题,于是根据博文解决异常:xxx,
设置了超时参数,但结果是无用。

对于2,由于使用的springboot, 1.5.3, 找到对应的MongoDB驱动版本(3.4.2),查看MongoDB版本(3.4.6)后,去官网查看是否对应,答案是可用,所以也不是版本驱动的问题。

对于3,这个大概率不会错,但是难保万一,于是专门对了一遍用户名、密码、端口、地址,结果是没有错。

对于4,嘴不相信的,因为是运维会配置好对应的权限。结果自己去服务器尝试telnet , 发现不通, 然后找运维解决,功能正常。

结论

对于找到问题,最可以依赖的只有事实和逻辑,不要被经验主义,先入为主的观念主导,生活也是如此。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值