[JAVA-2155] Mongo Async JDBC driver 3.0.4 and leak Created: 18/Mar/16 Updated: 11/Sep/19 Resolved: 21/Mar/16 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Async |
| Affects Version/s: | 3.0.4 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Blocker - P1 |
| Reporter: | pradeep | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
mongo db 2.6 |
||
| Attachments: |
|
| Description |
|
Mongo Async JDBC driver 3.0.4 and leak, When I am using the code in a stand alone java program I am getting result back and no issue. same code if i apply in a spring app , I am seeing that I never got result back and tomcat gave me below warning. On SinleResultCallbak apply method never get the result and I keep getting below error.
|
| Comments |
| Comment by pradeep [ 24/Mar/16 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
This is coming only if I am using asynch driver, if I removed it then I Thanks, On Thu, Mar 24, 2016 at 11:06 AM, Ross Lawley (JIRA) <jira@mongodb.org> | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Ross Lawley [ 24/Mar/16 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Looking at the error message its caused by:
You need to find the creator of the expiringMap-0 thread and ensure its stopped. I don't think its related to the Java Driver, perhaps asking on stackoverflow will yield an answer. Ross | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by pradeep [ 24/Mar/16 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I have created a predestry spring bean method and tried to close mongoClient still I don't see that threads are cleaning up.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Ross Lawley [ 21/Mar/16 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
No problems - could you provide insight into the cause of the issue and the solution you used? So to help any future users that have this issue. For future reference, the best place for questions regarding MongoDB usage or the Java driver specifics is the mongodb-user mailinglist or stackoverflow as you will reach a boarder audience there. All the best, Ross | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by pradeep [ 19/Mar/16 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks for help, please close the ticket. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by pradeep [ 18/Mar/16 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks Ross for help , it helped , ,after 5 calls I got one operation finished with this message : - Can't find a codec for class java.util.GregorianCalendar.org.bson.codecs.configuration.CodecConfigurationException: strange. I may be missing something here. why this error in spring app not in Stand alone program. Another question is what is the sla for call backs ? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Ross Lawley [ 18/Mar/16 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks for the logs, that clarifies the issue. Firstly the reported possible connection leak is because the MongoClient is not closed correctly. In the background the MongoClient has a thread that monitors the state of MongoDB. When you shutdown Tomcat you also need to call MongoClient#close(), so that it can shutdown the client correctly. Secondly, I can see it is calling the callback on the iterable as there is *Operation Finished* in the logs. You should always check the Throwable t value to see if there was an error when running the operation. If there is no error and the forEach block isn't called it means that the iterable was empty (eg. No matching Documents). I hope that helps clarify what is happening in the code. Ross | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by pradeep [ 18/Mar/16 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Another concern is why this program is not returning result. if I put same in a standalone program it return result within milliseconds. same db and from same machine , same editor. which indicates that thread are not getting back to pool. If needed we can do some screen sharing session. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by pradeep [ 18/Mar/16 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Attaching logs to review. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by pradeep [ 18/Mar/16 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
In logs if you notice this line , I waited more than 5 minutesto get response back yesterday and I never got response back from DB. The web application [ROOT] appears to have started a thread named [cluster-ClusterId {value='56ec3adea8a983067b788576', description='null'}-hostt:27017] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by pradeep [ 18/Mar/16 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Once I send a request and then I am shutting down the tomcat and seeing these error messages. Attaching log where I don't see any callback error. This is spring boot app so tomcat container is embedded one. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Ross Lawley [ 18/Mar/16 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
In the Spring app are you seeing any logs? If there was an error in a callback I would expect a "Callback onResult call produced an error" message. Having looked at the callback in the code above I can't see anything obvious regarding the reported leak. Regarding the leak itself, is that reported during normal running or when tomcat is stopped or restarted? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by pradeep [ 18/Mar/16 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Code to get data from DB :
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by pradeep [ 18/Mar/16 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
DB connectivity : -
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by pradeep [ 18/Mar/16 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks , Sure, I will put code in the couple of hours. As I said same code works fine in a stand alone java program I get the result from DB , but in spring app no result and apply method never called and if call my code multiple times I can see that it hit the onResult method. and threads name are keep changing. In app logs I don't see any error. if you want me to enable any debugging I can try that also. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Ross Lawley [ 18/Mar/16 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks for the ticket, can you provide some code? It could be a runtime error in the callback, the driver logs might provide some insight if that is the case. Ross |