Maison > Questions et réponses > le corps du texte
1. Récemment, j'utilise spring-boot et spring-data-mongo pour faire fonctionner mongodb
2. Je vérifie le journal du serveur tous les matins et constate que la même erreur est signalée. On estime que personne n'accède au serveur toute la nuit. L'erreur se produira une fois que quelqu'un accédera au serveur le lendemain
.3. Le journal des erreurs est :
07:51:35.185 [cluster-ClusterId{value='59295e6c3532f223626a2ca0', description='null'}-localhost:27017] INFO org.mongodb.driver.cluster - Exception in monitor thread while connecting to server localhost:27017
com.mongodb.MongoSocketReadTimeoutException: Timeout while receiving message
at com.mongodb.connection.InternalStreamConnection.translateReadException(InternalStreamConnection.java:477)
at com.mongodb.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:228)
at com.mongodb.connection.CommandHelper.receiveReply(CommandHelper.java:134)
at com.mongodb.connection.CommandHelper.receiveCommandResult(CommandHelper.java:121)
at com.mongodb.connection.CommandHelper.executeCommand(CommandHelper.java:32)
at com.mongodb.connection.InternalStreamConnectionInitializer.initializeConnectionDescription(InternalStreamConnectionInitializer.java:85)
at com.mongodb.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:45)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:116)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:127)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:171)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at com.mongodb.connection.SocketStream.read(SocketStream.java:85)
at com.mongodb.connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:494)
at com.mongodb.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:224)
... 8 common frames omitted
07:51:31.683 [cluster-ClusterId{value='59295e583532f22362cf3b92', description='null'}-localhost:27017] INFO org.mongodb.driver.cluster - Exception in monitor thread while connecting to server localhost:27017
com.mongodb.MongoSocketReadTimeoutException: Timeout while receiving message
at com.mongodb.connection.InternalStreamConnection.translateReadException(InternalStreamConnection.java:477)
at com.mongodb.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:228)
at com.mongodb.connection.CommandHelper.receiveReply(CommandHelper.java:134)
at com.mongodb.connection.CommandHelper.receiveCommandResult(CommandHelper.java:121)
at com.mongodb.connection.CommandHelper.executeCommand(CommandHelper.java:32)
at com.mongodb.connection.InternalStreamConnectionInitializer.initializeConnectionDescription(InternalStreamConnectionInitializer.java:85)
at com.mongodb.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:45)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:116)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:127)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:171)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at com.mongodb.connection.SocketStream.read(SocketStream.java:85)
at com.mongodb.connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:494)
at com.mongodb.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:224)
... 8 common frames omitted
07:51:35.780 [cluster-ClusterId{value='59295e403532f2236234b535', description='null'}-localhost:27017] INFO org.mongodb.driver.cluster - Exception in monitor thread while connecting to server localhost:27017
com.mongodb.MongoSocketReadTimeoutException: Timeout while receiving message
at com.mongodb.connection.InternalStreamConnection.translateReadException(InternalStreamConnection.java:477)
at com.mongodb.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:228)
at com.mongodb.connection.CommandHelper.receiveReply(CommandHelper.java:134)
at com.mongodb.connection.CommandHelper.receiveCommandResult(CommandHelper.java:121)
at com.mongodb.connection.CommandHelper.executeCommand(CommandHelper.java:32)
at com.mongodb.connection.InternalStreamConnectionInitializer.initializeConnectionDescription(InternalStreamConnectionInitializer.java:85)
at com.mongodb.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:45)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:116)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:127)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:171)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at com.mongodb.connection.SocketStream.read(SocketStream.java:85)
at com.mongodb.connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:494)
at com.mongodb.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:224)
... 8 common frames omitted
08:01:39.239 [cluster-ClusterId{value='59295e583532f22362cf3b92', description='null'}-localhost:27017] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:9, serverValue:828}] to localhost:27017
08:01:39.248 [cluster-ClusterId{value='59295e583532f22362cf3b92', description='null'}-localhost:27017] INFO org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 4, 4]}, minWireVersion=0, maxWireVersion=5, maxDocumentSize=16777216, roundTripTimeNanos=340319}
08:01:39.273 [cluster-ClusterId{value='59295e6c3532f223626a2ca0', description='null'}-localhost:27017] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:7, serverValue:827}] to localhost:27017
08:01:39.274 [cluster-ClusterId{value='59295e403532f2236234b535', description='null'}-localhost:27017] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:7, serverValue:826}] to localhost:27017
08:01:39.274 [cluster-ClusterId{value='59295e403532f2236234b535', description='null'}-localhost:27017] INFO org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 4, 4]}, minWireVersion=0, maxWireVersion=5, maxDocumentSize=16777216, roundTripTimeNanos=105791}
08:01:39.274 [cluster-ClusterId{value='59295e6c3532f223626a2ca0', description='null'}-localhost:27017] INFO org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 4, 4]}, minWireVersion=0, maxWireVersion=5, maxDocumentSize=16777216, roundTripTimeNanos=532381}
4. J'ai essayé quelques solutions et modifié le code reliant mongodb en :
new MongoClient(new ServerAddress(env.getProperty("mongo.host"), Integer.valueOf(env.getProperty("mongo.port"))), Arrays.asList(credential), MongoClientOptions.builder()
.socketTimeout(10000)
.minHeartbeatFrequency(25)
.heartbeatSocketTimeout(3000)
.socketKeepAlive(true)
.build());
A également modifié le temps de maintien en vie de l'ipv4 du serveur (Ubuntu) à 120 secondes.
Mais l'erreur est toujours là, j'espère que tout le monde pourra me donner quelques conseils, merci !
伊谢尔伦2017-05-31 10:37:10
Très probablement, MongoDB a lancé la connexion maintenue par Java (le statut est devenu CLOSE_WAIT
, et les données ne peuvent être envoyées mais ne peuvent plus être reçues. Vous pouvez penser à une solution à deux endroits : CLOSE_WAIT
,只能发数据但无法再收到),可以从两个地方想想办法:
把连接池配置好(这个貌似很复杂),或者干脆不用连接池,即socketKeepAlive
设成false
).
socketKeepAlive
sur false
;
Parce que vos problèmes apparaissent tous le matin, vous pouvez vérifier si MongoDB a une stratégie pour réinitialiser les connexions tôt le matin.
ringa_lee2017-05-31 10:37:10
1. Il se peut que le temps de requête soit trop long. Vous pouvez également consulter les informations de profilage ou du journal du serveur pour trouver les instructions avec des temps de requête relativement longs, telles que les instructions qui dépassent 10 secondes, pour voir si elles le peuvent. être optimisé ;
2. Augmentez le socketTimeout de manière appropriée pour voir si cette situation d'erreur peut être atténuée.
Pour référence.
J'adore MongoDB ! Amusez-vous!
La conférence du groupe d'utilisateurs de la communauté chinoise MongoDB 2017 à Pékin aura lieu bientôt, le 3 juin 2017, de 13h00 à 18h00
Il y a aussi des T-shirts et autres petits cadeaux ! héhé !
Veuillez vous inscrire