[JAVA-306] The com.mongodb.Mongo.close() method can return before the cleanup thread is finished Created: 24/Mar/11  Updated: 28/May/11  Resolved: 16/May/11

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: 2.5.2
Fix Version/s: 2.6

Type: Bug Priority: Major - P3
Reporter: Sean Reilly Assignee: Antoine Girbal
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

The method com.mongodb.Mongo.close() sets a signal that eventually tells the internal DBCleaner thread to close; which it correctly does. However, since the DBCleaner thread often sleeps, and cleaning up cursors could take a while, the thread will frequently not finish execution until after the close method returns. When this happens in apache tomcat, the following error is seen in tomcat's log files:

SEVERE: The web application [/someWebApp] appears to have started a thread named [MongoCleaner892931837] but has failed to stop it. This is very likely to create a memory leak.



 Comments   
Comment by auto [ 16/May/11 ]

Author:

{u'login': u'seanjreilly', u'name': u'Sean Reilly', u'email': u'seanjreilly@gmail.com'}

Message: Closing a Mongo instance now waits for the cleaner

http://jira.mongodb.org/browse/JAVA-306
Mongo.close() now waits for the DBCleaner thread to finish
before returning.
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/d8547e2ecca267c95605ca97a3d3adee22d01973

Comment by Sean Reilly [ 24/Mar/11 ]

I've committed a unit test and potential fix to github: https://github.com/seanjreilly/mongo-java-driver/commit/4d51cc32f6815c666c44ba6680f551b50da0f6cc

With this patch, tomcat no longer emits an error message during web application shutdown.

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