gpt4 book ai didi

java - mongodb连接抛出MongoSocketReadException

转载 作者:太空宇宙 更新时间:2023-11-04 12:30:09 26 4
gpt4 key购买 nike

总之,我遇到了一个奇怪的问题。

我有 3 台 MongoDB 服务器,并将它们组合成一个 replset——一台是主节点,另外 2 台是辅助节点。我的MongoDB客户端是Java MongoDB客户端,Spring环境。

我使用 haproxy 定向到 replset 节点。

有时当我连接到haproxy时,mongo客户端会抛出以下异常:

消息:发现异常:过早到达流末尾;嵌套异常是 com.mongodb.MongoSocketReadException:提前到达流末尾

当我重试时,它会消失,几分钟后它会再次出现。

我的 haproxy 配置如下所示:

global
daemon
user vcap
group vcap
log /dev/log daemon info
maxconn 4096

defaults
log global
option dontlognull
mode tcp
timeout connect 5000ms
timeout client 30000ms
timeout server 30000ms
retries 3
option redispatch

# admin gui
listen stats
bind :8080
mode http
stats enable
stats uri /stats

default-server on-error fastinter error-limit 3 inter 3000ms fastinter 1000ms downinter 300s fall 3

frontend fe_mongo_27027_tcp
bind 0.0.0.0:27027
mode tcp
option tcplog
use_backend be_mongo_27027_tcp

backend be_mongo_27027_tcp
mode tcp
option tcp-check
# mongodb wire protocol
tcp-check send-binary 3a000000 # Message Length (58)
tcp-check send-binary EEEEEEEE # Request ID (random value)
tcp-check send-binary 00000000 # Response To (nothing)
tcp-check send-binary d4070000 # OpCode (Query)
tcp-check send-binary 00000000 # Query Flags
tcp-check send-binary 61646d696e2e # fullCollectionName (admin.$cmd)
tcp-check send-binary 24636d6400 # continued
tcp-check send-binary 00000000 # NumToSkip
tcp-check send-binary FFFFFFFF # NumToReturn
# Start of Document
tcp-check send-binary 13000000 # Document Length (19)
tcp-check send-binary 10 # Type (Int32)
tcp-check send-binary 69736d617374657200 # ismaster:
tcp-check send-binary 01000000 # Value : 1
tcp-check send-binary 00 # Term

tcp-check expect binary 69736d61737465720001 #ismaster True
# mongodb check end

option tcplog
option tcpka

server mongodb-10.62.90.175 10.62.90.175:27017 check inter 2000

server mongodb-10.62.90.176 10.62.90.176:27017 check inter 2000

server mongodb-10.62.90.174 10.62.90.174:27017 check inter 2000

最佳答案

这是由于超时设置,连接已关闭,因此 mongo 客户端无法接收二进制文件,现在我删除了超时设置,它现在可以工作了。

关于java - mongodb连接抛出MongoSocketReadException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37935691/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com