[JAVA-1534] com.mongodb.DBPortPool gotError WARNING: emptying DBPortPool to /ip:port b/c of error Created: 06/Nov/14  Updated: 11/Sep/19  Resolved: 07/Nov/14

Status: Closed
Project: Java Driver
Component/s: Connection Management
Affects Version/s: 2.11.4
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Claire Lee Assignee: Unassigned
Resolution: Done Votes: 0
Labels: com.mongodb.DBPortPool, connection, socket
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

mongo-java-driver-2.11.4.jar, Java 8, Tomcat 8, MongoDB 2.6.3



 Description   

My JAVA application is run on Tomcat Server with a single MongoDB. This error occurs some times a day.

  • Here is an exception message.
    ----------------------------------------------------------------------------------------------------
    com.mongodb.DBPortPool gotError
    WARNING: emptying DBPortPool to /172.20.1.4:27017 b/c of error
    java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:189)
    at java.net.SocketInputStream.read(SocketInputStream.java:121)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
    at org.bson.io.Bits.readFully(Bits.java:46)
    at org.bson.io.Bits.readFully(Bits.java:33)
    at org.bson.io.Bits.readFully(Bits.java:28)
    at com.mongodb.Response.<init>(Response.java:40)
    at com.mongodb.DBPort.go(DBPort.java:142)
    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.DB.command(DB.java:262)
    at com.mongodb.DB.command(DB.java:244)
    at com.mongodb.DBCollection.getCount(DBCollection.java:985)
    at com.mongodb.DBCursor.size(DBCursor.java:602)
    at com.mysema.query.mongodb.MongodbQuery.list(MongodbQuery.java:271)
    at org.springframework.data.mongodb.repository.support.QueryDslMongoRepository.findAll(QueryDslMongoRepository.java:93)
    at sun.reflect.GeneratedMethodAccessor6078.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:358)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:343)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at com.sun.proxy.$Proxy586.findAll(Unknown Source)
    ----------------------------------------------------------------------------------------------------
  • The code about connecting MongoDB is not different. Here is the code.

MongoClientOptions options = MongoClientOptions.builder()
.connectionsPerHost(50).build();
MongoClient client = new MongoClient(new ServerAddress(dbHost, dbPort),
Arrays.asList(credential), options);
----------------------------------------------------------------------------------------------------
I can't even guess whether it's caused by a Network problem or a MongoDB java driver.

This issue is really worrying..Please, help me.



 Comments   
Comment by Ross Lawley [ 27/Jan/15 ]

Hi huoyingoo this ticket has been closed.

Please can you post your question to the mongodb user forum. It's a better place for your question and hopefully you'll get the answers you need there. Please remember to provide as much information as you can eg what driver version, mongodb version etc..

Regards,

Ross

Comment by huoyingoo [ 27/Jan/15 ]

I have met this exception too.and can not find some solution,while i open a page for a long time and no operation,and then request the connection to mongodb,it's probably happend.but the service not down,refresh the page,it's working normally.

it seems that after the mongodb server closed the a long connection,and mongo-java-driver dont know the current socket has been closed?

Comment by Jeffrey Yemin [ 07/Nov/14 ]

Connection reset is a confusing message, but I can almost guarantee you that it's not something that the driver itself is responsible for. Something is going on between your application and the MongoDB server its connected to that is resetting the socket.

I'm going to close this issue unless you have any other questions about the driver itself. In the future, please consider asking these types of questions in our user forum.

Thanks,
Jeff

Comment by Claire Lee [ 06/Nov/14 ]

Thank you for this comment. I cloned this issue mistakenly and it resulted in creating the issue (JAVA-1535). I am so sorry;; My purpose was to edit my issue, but I couldn't find Edit button;; Anyway, Can I ask you more about the issue? If there hasn't been any network issues between Tomcat Server and MongoDB server and MongoDB server never restarted, is there any possibility to occur this exception? Let me describe more details of this situation. The application has a scheduler to select a query to MongoDB every one minutes. When I checked the Tomcat server logs, it looked fine. But when I opened a web page, this exception occurred some times. If I reloaded the page and it opened and worked well. I googled this issue and found some articles (http://realizeideas.net/blog/view/michael/Azure-MongoDB-on-EC2-Connection-reset => the environment is different to mine but I found 'The reason of this is that Azure has global firewall which kill all idle connections in pool that are older then about 3 min' // https://forums.openshift.com/connection-reset-in-scale-app-and-spring-mongotemplate -> https://forums.openshift.com/connection-reset-in-scale-app-and-spring-mongotemplate => it suggests to use Spring Retry advice. // https://developer.ibm.com/answers/questions/8576/mongodb-emptying-dbportpool-to-ip-port-b-c-of-error-ioexception-authenticating-the-connection.html => It says 'The behavior I have seen on the mongodb server after 100 connections is to first accept then immediately close a handful of connections, then shutdown,') All articles made me more confused; I will ask the MongoDB administrator about the network status when the exception occurred but I really want to clarify the possible cause and eliminate my confusion. Thank you very much for your attention to this issue.

Comment by Jeffrey Yemin [ 06/Nov/14 ]

The is due to a network error, as evidenced by the "SocketException: Connection reset". This socket exception occurred while executing a count command against the server. The most common cause is that the MongoDB server (or a router sitting between the application and the MongoDB server) closed the connection. This can happen, for example, if the MongoDB server is restarted.

I suggest checking the server logs to see if you can find any correlating messages at the time of the log message in the Tomcat application.

Generated at Thu Feb 08 08:54:51 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.