Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-1271

Java driver does not clean up thread resources (sometimes)

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.12.0
    • Component/s: Error Handling
    • Labels:
      None
    • Environment:
      Tomcat 7.0.27

      In the case of a RuntimeException such as a ClassNotFoundException, the Java driver may not clean up all of its resources, in particular the non-daemon threads used for pool eviction (the PooledConnectionProvider.sizeMaintenanceTimer). This can cause web containers such as Tomcat to fail to shut down properly. The scenario is as follows:

      1. Deploy a web application which deploys a MongoClient connected to a 3 node replica set.
      2. Access the application
      3. Undeploy the application in Tomcat

      Even though MongoClient.close is called by the application, some threads will remain. Any replica set polling threads other than the primary along with threads for maintaining the pools. What happens here is the following:

      1. MongoClient.close() is called
      2. ...
      3. ConcurrentPool.close() is called
      4. In closing the pool tries to instantiate a CLDIterator. Since the jar containing the class has been removed a ClassNotFoundException is raised which fails termination of remaining threads.

      The PooledConnectionProvider should ensure that all threads created are shut down regardless of failures in the pool.close method. Likewise the other close methods should insulate themselves from such failures. Also, the threads Timer threads spawned for pool eviction should probably be set as daemon threads to avoid shutdown issues.

            Assignee:
            Unassigned Unassigned
            Reporter:
            clecompte Chris LeCompte
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: