这些是我在应用程序启动后反复收到的日志
2020-01-22T12:55:34,811 INFO [cluster-ClusterId{value='5e27f56499adc55f60198441', description='null'}-x:27017] com.mongodb.diagnostics.logging.SLF4JLogger: Opened connection [connectionId{localValue:429, serverValue:273700}] to x:27017
2020-01-22T12:55:34,856 INFO [cluster-ClusterId{value='5e27f56499adc55f60198441', description='null'}-x:27017] com.mongodb.diagnostics.logging.SLF4JLogger: Opened connection [connectionId{localValue:428, serverValue:275417}] to x:27017
2020-01-22T12:55:35,168 INFO [cluster-ClusterId{value='5e27f56499adc55f60198441', description='null'}-x:27017] com.mongodb.diagnostics.logging.SLF4JLogger: Monitor thread successfully connected to server with description ServerDescription{address=x:27017, type=REPLICA_SET_PRIMARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[4, 2, 2]}, minWireVersion=0, maxWireVersion=8, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=181132909, setName='x-0', canonicalAddress=x:27017, hosts=[x:27017, x:27017, x:27017], passives=[], arbiters=[], primary='x:27017', tagSet=TagSet{[Tag{name='region', value='AP_SOUTH_1'}, Tag{name='nodeType', value='ELECTABLE'}, Tag{name='provider', value='AWS'}]}, electionId=7fffffff000000000000003e, setVersion=2, lastWriteDate=Wed Jan 22 12:55:30 IST 2020, lastUpdateTimeNanos=180151204451076}
2020-01-22T12:55:29,659 INFO [cluster-ClusterId{value='5e27f56499adc55f60198441', description='null'}-x:27017] com.mongodb.diagnostics.logging.SLF4JLogger: Opened connection [connectionId{localValue:424, serverValue:276311}] to x:27017
2020-01-22T12:55:30,054 INFO [cluster-ClusterId{value='5e27f56199adc55f60198440', description='null'}-x:27017] com.mongodb.diagnostics.logging.SLF4JLogger: Opened connection [connectionId{localValue:425, serverValue:273700}] to x:27017
2020-01-22T12:55:33,603 INFO [cluster-ClusterId{value='5e27f56199adc55f60198440', description='null'}-x:27017] com.mongodb.diagnostics.logging.SLF4JLogger: Opened connection [connectionId{localValue:426, serverValue:278143}] to x:27017
2020-01-22T12:55:34,663 INFO [cluster-ClusterId{value='5e27f56199adc55f60198440', description='null'}-x:27017] com.mongodb.diagnostics.logging.SLF4JLogger: Opened connection [connectionId{localValue:427, serverValue:275417}] to x:27017
2020-01-22T12:55:34,742 INFO [cluster-ClusterId{value='5e27f56199adc55f60198440', description='null'}-x:27017] com.mongodb.diagnostics.logging.SLF4JLogger: Monitor thread successfully connected to server with description ServerDescription{address=x:27017, type=REPLICA_SET_PRIMARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[4, 2, 2]}, minWireVersion=0, maxWireVersion=8, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=133861489, setName='x-0', canonicalAddress=x:27017, hosts=[x:27017, x:27017, x:27017], passives=[], arbiters=[], primary='x:27017', tagSet=TagSet{[Tag{name='nodeType', value='ELECTABLE'}, Tag{name='provider', value='AWS'}, Tag{name='region', value='AP_SOUTH_1'}]}, electionId=7fffffff000000000000003e, setVersion=2, lastWriteDate=Wed Jan 22 12:55:30 IST 2020, lastUpdateTimeNanos=180150777860085}
2020-01-22T12:55:34,811 INFO [cluster-ClusterId{value='5e27f56499adc55f60198441', description='null'}-x:27017] com.mongodb.diagnostics.logging.SLF4JLogger: Opened connection [connectionId{localValue:429, serverValue:273700}] to x:27017
2020-01-22T12:55:34,856 INFO [cluster-ClusterId{value='5e27f56499adc55f60198441', description='null'}-x:27017] com.mongodb.diagnostics.logging.SLF4JLogger: Opened connection [connectionId{localValue:428, serverValue:275417}] to x:27017
集群是来自cloud mongo atlas的M0。 每当我们将某些 ip 列入白名单时,连接数就会激增到 100 以上(这是最大值)。 一旦我们从白名单中删除该 IP,连接就会断开。 奇怪的是,即使我们没有通过该 IP 上的网络服务器建立任何连接,连接也会激增。
这与监视器线程尝试重新连接有关,即使它已连接。
最佳答案
我们之前也遇到过类似的问题,即使我们只是将 IP 列入白名单,连接也会激增。这是一个奇怪的问题,因为我们没有从该白名单 IP 建立任何连接,但连接仍然激增。
但解决方案非常奇怪,我们重新启动其中一个开发人员系统。 我们可以怀疑的是,他之前通过 NoSQL Booster、终端或通过本地调试部署本身建立了许多连接。这些连接不会自行关闭,只要他的笔记本电脑连接到任何列入白名单的 IP,这些连接就会出现。
针对奇怪情况的非常简单的解决方案。也许您可以尝试重新启动系统。
关于java - 为什么我的 spring 应用程序不断打开与云图集 mongoDB 的新连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59855192/