com.mongodb.MongoException$Network: Read operation to server IP:27017 failed on database cfgDb

53 Views Asked by At

When my web program and mongo are deployed on different servers and they belong to the same intranet, this error will occasionally be reported. But if the web program and mongo are deployed on the same server, this error will not occur. What is the cause? The error message is as follows:

com.mongodb.MongoException$Network: Read operation to server XXXXX:27017 failed on database cfgDb
at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:298)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:269)
at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:84)
at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:66)
at com.mongodb.DBCursor.\_check(DBCursor.java:498)
at com.mongodb.DBCursor.\_hasNext(DBCursor.java:621)
at com.mongodb.DBCursor.hasNext(DBCursor.java:657)

The mongo version used is 3.2.21, and the java driver version is mongo-java-driver-2.13.1.jar Every time this error is reported, there will be this error:

Caused by: java.net.SocketException: Connection timed out (Write failed)
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111)
at java.net.SocketOutputStream.write(SocketOutputStream.java:155)
at org.bson.io.PoolOutputBuffer.pipe(PoolOutputBuffer.java:153)
at com.mongodb.OutMessage.pipe(OutMessage.java:236)
at com.mongodb.DBPort$1.execute(DBPort.java:163)
at com.mongodb.DBPort$1.execute(DBPort.java:158)
at com.mongodb.DBPort.doOperation(DBPort.java:187)
at com.mongodb.DBPort.call(DBPort.java:158)
at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:290)

or this error:

Caused by: java.net.SocketException: Connection reset
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:115)
at java.net.SocketOutputStream.write(SocketOutputStream.java:155)
at org.bson.io.PoolOutputBuffer.pipe(PoolOutputBuffer.java:153)
at com.mongodb.OutMessage.pipe(OutMessage.java:236)
at com.mongodb.DBPort$1.execute(DBPort.java:163)
at com.mongodb.DBPort$1.execute(DBPort.java:158)
at com.mongodb.DBPort.doOperation(DBPort.java:187)
at com.mongodb.DBPort.call(DBPort.java:158)
at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:290)

Several kernel parameters of server TCP are as follows:

vm.overcommit_memory = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 10
net.ipv4.route.gc_timeout = 100
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_max_syn_backlog = 32768
net.core.netdev_max_backlog = 32768
net.core.somaxconn = 32768
net.ipv4.tcp_mem = 78643200 104857600 157286400
net.ipv4.tcp_keepalive_intvl = 1
net.ipv4.tcp_keepalive_probes = 1
net.ipv4.tcp_max_tw_buckets = 262144
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
kernel.pid_max=1000000

How can I solve this problem? Please help me.

I looked at the slow query log of mongo. There is no query that is very slow. every operation is very fast. The server's network was also very good when the error was reported, and there was no network packet loss.What is the reason for not being able to connect to the database?

0

There are 0 best solutions below