Com.mongbb.DBPortPool gotError Warning: emptying DBPortPool to / IP: 27017 b / c errors using spring MongoTemplate

use org.springframework.data.mongodb.core.MongoTemplate

It seems MongoDB Driver cannot remove a dropped socket from the connection from the pool until your code tries to use it

follow these steps:

2013-9-2 9:13:16 com.mongodb.DBPortPool gotError θ­¦ε‘Š: emptying DBPortPool to /IP:27017 b/c of error java.net.SocketException: Connection reset by peer: socket write error at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92) at java.net.SocketOutputStream.write(SocketOutputStream.java:136) at org.bson.io.PoolOutputBuffer.pipe(PoolOutputBuffer.java:129) at com.mongodb.OutMessage.pipe(OutMessage.java:236) at com.mongodb.DBPort.go(DBPort.java:133) at com.mongodb.DBPort.call(DBPort.java:92) at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:244) at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:216) at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:288) at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:273) at com.mongodb.DBCursor._check(DBCursor.java:368) at com.mongodb.DBCursor._hasNext(DBCursor.java:459) at com.mongodb.DBCursor.hasNext(DBCursor.java:484) at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1530) at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1336) 

Reading server / IP operation: 27017 failure in the database database; nested exception - com.mongodb.MongoException $ Network: reading operation on server / IP: 27017 could not create DB database

is there any other solution besides try catch?

+4
source share
1 answer

The MongoDB Java driver can only report that the connection is dead when you start using it - it does not periodically check the connections (for example) to verify that they are still alive, because this can automatically affect performance. However, if you receive an IOException in one connection, all other connections will be closed and deleted, after which new connections will be created.

This means applications must catch Exceptions and retry if necessary. In fact, your application is the best place to decide what to do in exceptional circumstances, such as disconnections.

+5
source

Source: https://habr.com/ru/post/1500066/


All Articles