作者:xupengkunwudi163899 | 来源:互联网 | 2023-09-15 20:53
在线上看到了这样的异常:
1 2 3 4 5
| com.mongodb.MongoQueryException: Query failed with error code 6 and error message 'Connection reset by peer' on server XXX.XXX.XXX.XXX:27017
at com.mongodb.operation.QueryHelper.translateCommandException(QueryHelper.java:31)
at com.mongodb.operation.QueryBatchCursor.getMore(QueryBatchCursor.java:213)
at com.mongodb.operation.QueryBatchCursor.hasNext(QueryBatchCursor.java:103)
at com.mongodb.MongoBatchCursorAdapter.hasNext(MongoBatchCursorAdapter.java:46) |
搞不清楚这个错误是怎么回事? 我在本地也尝试去人工制造这个问题 也不成功
尝试一:
通过防火墙规则来禁止访问线上MongoDB 模拟网络异常
1 2 3 4 5 6 7 8 9 10 11 12
| # Mac中的命令 Linux中可以用iptables
(sudo pfctl -sr 2>/dev/null; echo "block drop quick on en0 proto tcp from any to XXX.XXX.XXX.XXX port = 27017") | sudo pfctl -f - 2>/dev/null
Caused by: java.net.ConnectException: Operation timed out
at java.net.PlainSocketImpl.socketConnect(Native Method) ~[?:1.8.0_91]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[?:1.8.0_91]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[?:1.8.0_91]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[?:1.8.0_91]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[?:1.8.0_91]
at java.net.Socket.connect(Socket.java:589) ~[?:1.8.0_91]
at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:57) ~[mongo-java-driver-3.4.2.jar:?]
at com.mongodb.connection.SocketStream.open(SocketStream.java:58) ~[mongo-java-driver-3.4.2.jar:?] |
尝试二
直接关闭wifi 模拟网络异常
1 2 3 4 5 6 7 8 9
| Caused by: java.net.ConnectException: Network is unreachable
at java.net.PlainSocketImpl.socketConnect(Native Method) ~[?:1.8.0_91]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[?:1.8.0_91]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[?:1.8.0_91]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[?:1.8.0_91]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[?:1.8.0_91]
at java.net.Socket.connect(Socket.java:589) ~[?:1.8.0_91]
at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:57) ~[mongo-java-driver-3.4.2.jar:?]
at com.mongodb.connection.SocketStream.open(SocketStream.java:58) ~[mongo-java-driver-3.4.2.jar:?] |
尝试三
在cursor的过程中 显式杀死MongoDB服务进程 当然是本地的 不是线上的
1 2 3 4 5 6 7 8 9
| Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method) ~[?:1.8.0_91]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[?:1.8.0_91]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[?:1.8.0_91]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[?:1.8.0_91]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[?:1.8.0_91]
at java.net.Socket.connect(Socket.java:589) ~[?:1.8.0_91]
at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:57) ~[mongo-java-driver-3.4.2.jar:?]
at com.mongodb.connection.SocketStream.open(SocketStream.java:58) ~[mongo-java-driver-3.4.2.jar:?] |
线上的错误到底是什么原因导致的呢?本地该怎么复现这个错误呢?