Yiheng Li
Yiheng Li

Reputation: 145

com.mongodb.DBPortPool gotError Warning: emptying DBPortPool to /IP:27017 b/c of error using spring MongoTemplate

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

it seems MongoDB Driver can't remove dropped socket from connection from pool until your code try use it

error as follow:

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)

Read operation to server /IP:27017 failed on database DB; nested exception is com.mongodb.MongoException$Network: Read operation to server /IP:27017 failed on database DB

is there any other solution except try catch?

Upvotes: 4

Views: 4480

Answers (1)

Trisha
Trisha

Reputation: 3931

The MongoDB Java driver can only tell a connection is dead when you start to use it - it doesn't periodically check connections (for example) to check they're still alive because doing this automatically could have a performance impact. However, if you get an IOException in a single connection, all other connections will be closed and removed so new connections will be created afterwards.

It does mean that applications have a responsibility to catch Exceptions and perform a retry if appropriate. Really your application is the best place to decide what to do in exceptional circumstances like connections disappearing.

Upvotes: 5

Related Questions