Mongo客户端尝试关闭不存在/创建的连接,并由于MongoSocketReadException失败而失败:过早到达流的结尾

时间:2018-08-07 21:10:12

标签: java spring mongodb driver

当我尝试关闭mongo连接时,在调试模式下看到很多“ com.mongodb.MongoSocketReadException:过早到达流尾”的应用日志。到目前为止,我的分析是,我没有看到按照格式connectionId {localValue:8}

的连接ID在日志中创建了连接

注意:相同的代码在org.mongodb:mongodb-driver:3.4.2上也能正常工作,但在3.6.3中看到警告

Mongo客户端版本#3.6.3 Mongo Server版本号3.2.6(3个节点副本集) Mongo依赖项#org.springframework.data:spring-data-mongodb:1.8.2.RELEASE,org.mongodb:mongodb-driver:3.6.3

我确实参考了Mongo Java Driver -prematurely reached end of stream exception?,并尝试了以下设置,但没有帮助。

Mongo客户端配置

<mongo:mongo-client id="sslmongosfp" replica-set="${mongodb.replication.set}" credentials="${MONGO_USER}@${mongodb.dbname}">
    <mongo:client-options ssl="true"
      socket-keep-alive="${mongo.socketKeepAlive:true}"
      socket-timeout="${mongo.socketTimeout:180000}"
      heartbeat-connect-timeout="${mongo.heartbeat.connectTimeout:60000}"
      heartbeat-socket-timeout="${mongo.socketTimeout:180000}"
      max-connection-idle-time="${mongo.max.connection.idle:300000}" />
</mongo:mongo-client>

我的应用程序连接到同一副本集上的2个不同架构。

使用相关信息过滤的应用程序日志

[localhost-startStop-1] 2018-08-07 12:39:57,546  org.mongodb.driver.cluster - Cluster created with settings {hosts=[MyServer1:27017, MyServer3:27017, MyServer2:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
[localhost-startStop-1] 2018-08-07 12:39:57,552  org.mongodb.driver.cluster - Adding discovered server MyServer1:27017 to client view of cluster
[MaintenanceTimer-1-thread-1] 2018-08-07 12:39:57,585  org.mongodb.driver.connection - Pruning pooled connections to MyServer1:27017
[localhost-startStop-1] 2018-08-07 12:39:57,609  org.mongodb.driver.cluster - Adding discovered server MyServer3:27017 to client view of cluster
[MaintenanceTimer-2-thread-1] 2018-08-07 12:39:57,610  org.mongodb.driver.connection - Pruning pooled connections to MyServer3:27017
[localhost-startStop-1] 2018-08-07 12:39:57,611  org.mongodb.driver.cluster - Adding discovered server MyServer2:27017 to client view of cluster
[MaintenanceTimer-3-thread-1] 2018-08-07 12:39:57,612  org.mongodb.driver.connection - Pruning pooled connections to MyServer2:27017
[localhost-startStop-1] 2018-08-07 12:39:57,616  org.mongodb.driver.cluster - Updating cluster description to  {type=UNKNOWN, servers=[{address=MyServer1:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer2:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer3:27017, type=UNKNOWN, state=CONNECTING}]
[localhost-startStop-1] 2018-08-07 12:39:57,879  org.mongodb.driver.cluster - Cluster created with settings {hosts=[MyServer1:27017, MyServer3:27017, MyServer2:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
[localhost-startStop-1] 2018-08-07 12:39:57,879  org.mongodb.driver.cluster - Adding discovered server MyServer1:27017 to client view of cluster
[MaintenanceTimer-5-thread-1] 2018-08-07 12:39:57,880  org.mongodb.driver.connection - Pruning pooled connections to MyServer1:27017
[localhost-startStop-1] 2018-08-07 12:39:57,881  org.mongodb.driver.cluster - Adding discovered server MyServer3:27017 to client view of cluster
[MaintenanceTimer-6-thread-1] 2018-08-07 12:39:57,882  org.mongodb.driver.connection - Pruning pooled connections to MyServer3:27017
[localhost-startStop-1] 2018-08-07 12:39:57,882  org.mongodb.driver.cluster - Adding discovered server MyServer2:27017 to client view of cluster
[MaintenanceTimer-7-thread-1] 2018-08-07 12:39:57,885  org.mongodb.driver.connection - Pruning pooled connections to MyServer2:27017
[localhost-startStop-1] 2018-08-07 12:39:57,886  org.mongodb.driver.cluster - Updating cluster description to  {type=UNKNOWN, servers=[{address=MyServer1:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer2:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer3:27017, type=UNKNOWN, state=CONNECTING}]
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,168  org.mongodb.driver.connection - Opened connection [connectionId{localValue:2, serverValue:41448917}] to MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,168  org.mongodb.driver.cluster - Checking status of MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer2:27017] 2018-08-07 12:39:58,173  org.mongodb.driver.connection - Opened connection [connectionId{localValue:3, serverValue:41047679}] to MyServer2:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer2:27017] 2018-08-07 12:39:58,173  org.mongodb.driver.cluster - Checking status of MyServer2:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer2:27017] 2018-08-07 12:39:58,215  org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=MyServer2:27017, type=REPLICA_SET_SECONDARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 2, 6]}, minWireVersion=0, maxWireVersion=4, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=null, roundTripTimeNanos=40007177, setName='rs0', canonicalAddress=MyServer2:27017, hosts=[MyServer1:27017, MyServer2:27017, MyServer3:27017], passives=[], arbiters=[], primary='MyServer1:27017', tagSet=TagSet{[]}, electionId=null, setVersion=11, lastWriteDate=null, lastUpdateTimeNanos=634155407285407}
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,215  org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 2, 6]}, minWireVersion=0, maxWireVersion=4, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=null, roundTripTimeNanos=42769620, setName='rs0', canonicalAddress=MyServer1:27017, hosts=[MyServer1:27017, MyServer2:27017, MyServer3:27017], passives=[], arbiters=[], primary='MyServer1:27017', tagSet=TagSet{[]}, electionId=7fffffff000000000000002d, setVersion=11, lastWriteDate=null, lastUpdateTimeNanos=634155408436207}
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,218  org.mongodb.driver.cluster - Discovered cluster type of REPLICA_SET
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,219  org.mongodb.driver.cluster - Setting max election id to 7fffffff000000000000002d from replica set primary MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,220  org.mongodb.driver.cluster - Setting max set version to 11 from replica set primary MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,220  org.mongodb.driver.cluster - Discovered replica set primary MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,220  org.mongodb.driver.cluster - Updating cluster description to  {type=REPLICA_SET, servers=[{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, roundTripTime=42.8 ms, state=CONNECTED}, {address=MyServer2:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer3:27017, type=UNKNOWN, state=CONNECTING}]
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer2:27017] 2018-08-07 12:39:58,221  org.mongodb.driver.cluster - Updating cluster description to  {type=REPLICA_SET, servers=[{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, roundTripTime=42.8 ms, state=CONNECTED}, {address=MyServer2:27017, type=REPLICA_SET_SECONDARY, roundTripTime=40.0 ms, state=CONNECTED}, {address=MyServer3:27017, type=UNKNOWN, state=CONNECTING}]
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,296  org.mongodb.driver.connection - Opened connection [connectionId{localValue:4, serverValue:41448920}] to MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,296  org.mongodb.driver.cluster - Checking status of MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer2:27017] 2018-08-07 12:39:58,296  org.mongodb.driver.connection - Opened connection [connectionId{localValue:6, serverValue:41047689}] to MyServer2:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer2:27017] 2018-08-07 12:39:58,296  org.mongodb.driver.cluster - Checking status of MyServer2:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer3:27017] 2018-08-07 12:39:58,310  org.mongodb.driver.connection - Opened connection [connectionId{localValue:1, serverValue:15360985}] to MyServer3:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer3:27017] 2018-08-07 12:39:58,311  org.mongodb.driver.cluster - Checking status of MyServer3:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,335  org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 2, 6]}, minWireVersion=0, maxWireVersion=4, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=null, roundTripTimeNanos=38447323, setName='rs0', canonicalAddress=MyServer1:27017, hosts=[MyServer1:27017, MyServer2:27017, MyServer3:27017], passives=[], arbiters=[], primary='MyServer1:27017', tagSet=TagSet{[]}, electionId=7fffffff000000000000002d, setVersion=11, lastWriteDate=null, lastUpdateTimeNanos=634155527879863}
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer2:27017] 2018-08-07 12:39:58,335  org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=MyServer2:27017, type=REPLICA_SET_SECONDARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 2, 6]}, minWireVersion=0, maxWireVersion=4, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=null, roundTripTimeNanos=38707927, setName='rs0', canonicalAddress=MyServer2:27017, hosts=[MyServer1:27017, MyServer2:27017, MyServer3:27017], passives=[], arbiters=[], primary='MyServer1:27017', tagSet=TagSet{[]}, electionId=null, setVersion=11, lastWriteDate=null, lastUpdateTimeNanos=634155528294115}
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,336  org.mongodb.driver.cluster - Discovered cluster type of REPLICA_SET
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,336  org.mongodb.driver.cluster - Setting max election id to 7fffffff000000000000002d from replica set primary MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,336  org.mongodb.driver.cluster - Setting max set version to 11 from replica set primary MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,336  org.mongodb.driver.cluster - Discovered replica set primary MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer1:27017] 2018-08-07 12:39:58,336  org.mongodb.driver.cluster - Updating cluster description to  {type=REPLICA_SET, servers=[{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, roundTripTime=38.4 ms, state=CONNECTED}, {address=MyServer2:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer3:27017, type=UNKNOWN, state=CONNECTING}]
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer2:27017] 2018-08-07 12:39:58,336  org.mongodb.driver.cluster - Updating cluster description to  {type=REPLICA_SET, servers=[{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, roundTripTime=38.4 ms, state=CONNECTED}, {address=MyServer2:27017, type=REPLICA_SET_SECONDARY, roundTripTime=38.7 ms, state=CONNECTED}, {address=MyServer3:27017, type=UNKNOWN, state=CONNECTING}]
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer3:27017] 2018-08-07 12:39:58,577  org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=MyServer3:27017, type=REPLICA_SET_SECONDARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 2, 6]}, minWireVersion=0, maxWireVersion=4, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=null, roundTripTimeNanos=266413679, setName='rs0', canonicalAddress=MyServer3:27017, hosts=[MyServer1:27017, MyServer2:27017, MyServer3:27017], passives=[], arbiters=[], primary='MyServer1:27017', tagSet=TagSet{[]}, electionId=null, setVersion=11, lastWriteDate=null, lastUpdateTimeNanos=634155770298051}
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer3:27017] 2018-08-07 12:39:58,578  org.mongodb.driver.cluster - Updating cluster description to  {type=REPLICA_SET, servers=[{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, roundTripTime=42.8 ms, state=CONNECTED}, {address=MyServer2:27017, type=REPLICA_SET_SECONDARY, roundTripTime=40.0 ms, state=CONNECTED}, {address=MyServer3:27017, type=REPLICA_SET_SECONDARY, roundTripTime=266.4 ms, state=CONNECTED}]
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer3:27017] 2018-08-07 12:39:58,626  org.mongodb.driver.connection - Opened connection [connectionId{localValue:5, serverValue:15360986}] to MyServer3:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer3:27017] 2018-08-07 12:39:58,626  org.mongodb.driver.cluster - Checking status of MyServer3:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer3:27017] 2018-08-07 12:39:58,677  org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=MyServer3:27017, type=REPLICA_SET_SECONDARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 2, 6]}, minWireVersion=0, maxWireVersion=4, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=null, roundTripTimeNanos=50611106, setName='rs0', canonicalAddress=MyServer3:27017, hosts=[MyServer1:27017, MyServer2:27017, MyServer3:27017], passives=[], arbiters=[], primary='MyServer1:27017', tagSet=TagSet{[]}, electionId=null, setVersion=11, lastWriteDate=null, lastUpdateTimeNanos=634155870321060}
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer3:27017] 2018-08-07 12:39:58,678  org.mongodb.driver.cluster - Updating cluster description to  {type=REPLICA_SET, servers=[{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, roundTripTime=38.4 ms, state=CONNECTED}, {address=MyServer2:27017, type=REPLICA_SET_SECONDARY, roundTripTime=38.7 ms, state=CONNECTED}, {address=MyServer3:27017, type=REPLICA_SET_SECONDARY, roundTripTime=50.6 ms, state=CONNECTED}]
[localhost-startStop-1] 2018-08-07 12:40:00,930  org.mongodb.driver.connection - Opened connection [connectionId{localValue:7, serverValue:41448934}] to MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer1:27017] 2018-08-07 12:40:08,223  org.mongodb.driver.cluster - Checking status of MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer2:27017] 2018-08-07 12:40:08,223  org.mongodb.driver.cluster - Checking status of MyServer2:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer1:27017] 2018-08-07 12:40:08,256  org.mongodb.driver.cluster - Updating cluster description to  {type=REPLICA_SET, servers=[{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, roundTripTime=40.7 ms, state=CONNECTED}, {address=MyServer2:27017, type=REPLICA_SET_SECONDARY, roundTripTime=40.0 ms, state=CONNECTED}, {address=MyServer3:27017, type=REPLICA_SET_SECONDARY, roundTripTime=266.4 ms, state=CONNECTED}]
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer2:27017] 2018-08-07 12:40:08,262  org.mongodb.driver.cluster - Updating cluster description to  {type=REPLICA_SET, servers=[{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, roundTripTime=40.7 ms, state=CONNECTED}, {address=MyServer2:27017, type=REPLICA_SET_SECONDARY, roundTripTime=39.5 ms, state=CONNECTED}, {address=MyServer3:27017, type=REPLICA_SET_SECONDARY, roundTripTime=266.4 ms, state=CONNECTED}]
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer1:27017] 2018-08-07 12:40:08,339  org.mongodb.driver.cluster - Checking status of MyServer1:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer2:27017] 2018-08-07 12:40:08,339  org.mongodb.driver.cluster - Checking status of MyServer2:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer2:27017] 2018-08-07 12:40:08,436  org.mongodb.driver.cluster - Updating cluster description to  {type=REPLICA_SET, servers=[{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, roundTripTime=38.4 ms, state=CONNECTED}, {address=MyServer2:27017, type=REPLICA_SET_SECONDARY, roundTripTime=50.2 ms, state=CONNECTED}, {address=MyServer3:27017, type=REPLICA_SET_SECONDARY, roundTripTime=50.6 ms, state=CONNECTED}]
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer1:27017] 2018-08-07 12:40:08,441  org.mongodb.driver.cluster - Updating cluster description to  {type=REPLICA_SET, servers=[{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, roundTripTime=51.0 ms, state=CONNECTED}, {address=MyServer2:27017, type=REPLICA_SET_SECONDARY, roundTripTime=50.2 ms, state=CONNECTED}, {address=MyServer3:27017, type=REPLICA_SET_SECONDARY, roundTripTime=50.6 ms, state=CONNECTED}]
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer3:27017] 2018-08-07 12:40:08,581  org.mongodb.driver.cluster - Checking status of MyServer3:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6a', description='null'}-MyServer3:27017] 2018-08-07 12:40:08,631  org.mongodb.driver.cluster - Updating cluster description to  {type=REPLICA_SET, servers=[{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, roundTripTime=40.7 ms, state=CONNECTED}, {address=MyServer2:27017, type=REPLICA_SET_SECONDARY, roundTripTime=39.5 ms, state=CONNECTED}, {address=MyServer3:27017, type=REPLICA_SET_SECONDARY, roundTripTime=222.9 ms, state=CONNECTED}]
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer3:27017] 2018-08-07 12:40:08,681  org.mongodb.driver.cluster - Checking status of MyServer3:27017
[cluster-ClusterId{value='5b69cb5dd33cf25160031d6b', description='null'}-MyServer3:27017] 2018-08-07 12:40:08,735  org.mongodb.driver.cluster - Updating cluster description to  {type=REPLICA_SET, servers=[{address=MyServer1:27017, type=REPLICA_SET_PRIMARY, roundTripTime=51.0 ms, state=CONNECTED}, {address=MyServer2:27017, type=REPLICA_SET_SECONDARY, roundTripTime=50.2 ms, state=CONNECTED}, {address=MyServer3:27017, type=REPLICA_SET_SECONDARY, roundTripTime=50.2 ms, state=CONNECTED}]
[localhost-startStop-1] 2018-08-07 12:40:11,749  org.mongodb.driver.cluster - Cluster created with settings {hosts=[MyServer1:27017, MyServer3:27017, MyServer2:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
[localhost-startStop-1] 2018-08-07 12:40:11,749  org.mongodb.driver.cluster - Adding discovered server MyServer1:27017 to client view of cluster
[MaintenanceTimer-9-thread-1] 2018-08-07 12:40:11,750  org.mongodb.driver.connection - Pruning pooled connections to MyServer1:27017
[localhost-startStop-1] 2018-08-07 12:40:11,751  org.mongodb.driver.cluster - Adding discovered server MyServer3:27017 to client view of cluster
[MaintenanceTimer-10-thread-1] 2018-08-07 12:40:11,753  org.mongodb.driver.connection - Pruning pooled connections to MyServer3:27017
[localhost-startStop-1] 2018-08-07 12:40:11,755  org.mongodb.driver.cluster - Adding discovered server MyServer2:27017 to client view of cluster
[MaintenanceTimer-11-thread-1] 2018-08-07 12:40:11,757  org.mongodb.driver.connection - Pruning pooled connections to MyServer2:27017
[localhost-startStop-1] 2018-08-07 12:40:11,759  org.mongodb.driver.cluster - Updating cluster description to  {type=UNKNOWN, servers=[{address=MyServer1:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer2:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer3:27017, type=UNKNOWN, state=CONNECTING}]
[localhost-startStop-1] 2018-08-07 12:40:11,765  org.mongodb.driver.cluster - Cluster created with settings {hosts=[MyServer1:27017, MyServer3:27017, MyServer2:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
[localhost-startStop-1] 2018-08-07 12:40:11,765  org.mongodb.driver.cluster - Adding discovered server MyServer1:27017 to client view of cluster
[MaintenanceTimer-13-thread-1] 2018-08-07 12:40:11,767  org.mongodb.driver.connection - Pruning pooled connections to MyServer1:27017
[localhost-startStop-1] 2018-08-07 12:40:11,767  org.mongodb.driver.cluster - Adding discovered server MyServer3:27017 to client view of cluster
[MaintenanceTimer-14-thread-1] 2018-08-07 12:40:11,769  org.mongodb.driver.connection - Pruning pooled connections to MyServer3:27017
[localhost-startStop-1] 2018-08-07 12:40:11,770  org.mongodb.driver.cluster - Adding discovered server MyServer2:27017 to client view of cluster
[MaintenanceTimer-15-thread-1] 2018-08-07 12:40:11,772  org.mongodb.driver.connection - Pruning pooled connections to MyServer2:27017
[localhost-startStop-1] 2018-08-07 12:40:11,774  org.mongodb.driver.cluster - Updating cluster description to  {type=UNKNOWN, servers=[{address=MyServer1:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer2:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer3:27017, type=UNKNOWN, state=CONNECTING}]
[localhost-startStop-1] 2018-08-07 12:40:11,787  org.mongodb.driver.cluster - Cluster created with settings {hosts=[MyServer1:27017, MyServer3:27017, MyServer2:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
[localhost-startStop-1] 2018-08-07 12:40:11,787  org.mongodb.driver.cluster - Adding discovered server MyServer1:27017 to client view of cluster
[MaintenanceTimer-17-thread-1] 2018-08-07 12:40:11,788  org.mongodb.driver.connection - Pruning pooled connections to MyServer1:27017
[localhost-startStop-1] 2018-08-07 12:40:11,788  org.mongodb.driver.cluster - Adding discovered server MyServer3:27017 to client view of cluster
[MaintenanceTimer-18-thread-1] 2018-08-07 12:40:11,789  org.mongodb.driver.connection - Pruning pooled connections to MyServer3:27017
[localhost-startStop-1] 2018-08-07 12:40:11,790  org.mongodb.driver.cluster - Adding discovered server MyServer2:27017 to client view of cluster
[MaintenanceTimer-19-thread-1] 2018-08-07 12:40:11,791  org.mongodb.driver.connection - Pruning pooled connections to MyServer2:27017
[localhost-startStop-1] 2018-08-07 12:40:11,792  org.mongodb.driver.cluster - Updating cluster description to  {type=UNKNOWN, servers=[{address=MyServer1:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer2:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer3:27017, type=UNKNOWN, state=CONNECTING}]
[localhost-startStop-1] 2018-08-07 12:40:11,795  org.mongodb.driver.cluster - Cluster created with settings {hosts=[MyServer1:27017, MyServer3:27017, MyServer2:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
[localhost-startStop-1] 2018-08-07 12:40:11,795  org.mongodb.driver.cluster - Adding discovered server MyServer1:27017 to client view of cluster
[MaintenanceTimer-21-thread-1] 2018-08-07 12:40:11,796  org.mongodb.driver.connection - Pruning pooled connections to MyServer1:27017
[localhost-startStop-1] 2018-08-07 12:40:11,797  org.mongodb.driver.cluster - Adding discovered server MyServer3:27017 to client view of cluster
[MaintenanceTimer-22-thread-1] 2018-08-07 12:40:11,798  org.mongodb.driver.connection - Pruning pooled connections to MyServer3:27017
[localhost-startStop-1] 2018-08-07 12:40:11,799  org.mongodb.driver.cluster - Adding discovered server MyServer2:27017 to client view of cluster
[MaintenanceTimer-23-thread-1] 2018-08-07 12:40:11,801  org.mongodb.driver.connection - Pruning pooled connections to MyServer2:27017
[localhost-startStop-1] 2018-08-07 12:40:11,802  org.mongodb.driver.cluster - Updating cluster description to  {type=UNKNOWN, servers=[{address=MyServer1:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer2:27017, type=UNKNOWN, state=CONNECTING}, {address=MyServer3:27017, type=UNKNOWN, state=CONNECTING}]
[cluster-ClusterId{value='5b69cb6bd33cf25160031d6c', description='null'}-MyServer1:27017] 2018-08-07 12:40:11,865  org.mongodb.driver.connection - Closing connection connectionId{localValue:8}
[cluster-ClusterId{value='5b69cb6bd33cf25160031d6c', description='null'}-MyServer1:27017] 2018-08-07 12:40:11,865  org.mongodb.driver.cluster - Exception in monitor thread while connecting to server MyServer1:27017
com.mongodb.MongoSocketReadException: Prematurely reached end of stream
    at com.mongodb.connection.SocketStream.read(SocketStream.java:87)

有用的信息

  

我的应用程序日志第一条语句开始于@ 2018-08-07 12:39:47,040

     

提前到流结束@ 2018-08-07 12:40:11,865   并且此错误将永远重复。

1 个答案:

答案 0 :(得分:0)

从下面的日志中,我发现mongo客户端选项设置不正确 使用设置{hosts = [MyServer1:27017,MyServer3:27017,MyServer2:27017],创建模式= MULTIPLE, requiredClusterType = UNKNOWN ,serverSelectionTimeout ='30000 ms',maxWaitQueueSize = 500}

更新我的mongo配置以使用以下功能可以成功完成

<bean id="mongosfpUri" class="com.mongodb.MongoClientURI">
    <!-- refer https://docs.mongodb.com/manual/reference/connection-string/ -->
    <constructor-arg value="${mongodb.uri}"/>
</bean>

<bean id="mongosfp" class="com.mongodb.MongoClient">
    <constructor-arg ref="mongosfpUri"/>
</bean>

<mongo:db-factory id="mongoDbFactory" dbname="${mongodb.dbname}" mongo-ref="mongosfp" />

<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
    <constructor-arg ref="mongoDbFactory" />
    <constructor-arg ref="mongoConverter" />
</bean>

<bean id="mongoConverter" class="org.springframework.data.mongodb.core.convert.MappingMongoConverter">
    <constructor-arg ref="mongoDbFactory" />
    <constructor-arg>
        <bean class="org.springframework.data.mongodb.core.mapping.MongoMappingContext" />
    </constructor-arg>
    <property name="mapKeyDotReplacement" value="%2E" />
</bean>

这是样本mongodb.uri

mongodb.uri=mongodb://user:password@MyServer1:27017,MyServer2:27017,MyServer3:27017/mydb?replicaSet=rs0&ssl=true&sslInvalidHostNameAllowed=true&heartbeatFrequencyMS=10000