Java Driver
  1. Java Driver
  2. JAVA-306

The com.mongodb.Mongo.close() method can return before the cleanup thread is finished

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major - P3 Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.5.2
    • Fix Version/s: 2.6
    • Component/s: None
    • Labels:
      None
    • Operating System:
      ALL
    • # Replies:
      2
    • Last comment by Customer:
      false

      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.

        Activity

        Hide
        Sean Reilly
        added a comment -

        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.

        Show
        Sean Reilly
        added a comment - 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.
        Hide
        auto
        added a comment -

        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

        Show
        auto
        added a comment - 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

          People

          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since reply:
              2 years, 49 weeks, 1 day ago
              Date of 1st Reply: