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

Possible leak in Java 2.2 Driver with ReplicaSetStatus$Updater

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.3
    • Affects Version/s: 2.2
    • Component/s: None
    • None

      There appears to be a leak in the latest Mongo
      Driver. It would be most pronounced in a web app where you'd have
      multiple instances of Mongo being created, perhaps even created over
      and over during development as an application is reinitialized but the
      server (i.e. the VM) itself isn't actually restarted. I'm doing this
      within the context of ColdFusion, but this would be true of any
      container-based java app.

      To replicate, you should just need to create multiple instances of
      Mongo (with ServerAddresses constructor) and let them go out of scope
      as they normally would... maybe it's a singleton object that
      reinitializes its internal Mongo instance or something.

      What I'm seeing is that those Mongo instances stay around forever. If
      I'm reading the output of Eclipse's Memory Analyzer correctly, it's
      due to ReplicaSetStatus$Updater.

      I haven't read the source, but it appears that this spawns a thread
      that presumably checks for replica set members' status. However,
      that's keeping these objects alive even after the request that spawned
      them ends.

      In the forums, Eliot suggested calling Mongo.close(). I did that and observed two things:

      1) After doing so and taking a heap dump, the ReplicaSetStatus$Updater instances still remained. This was also evidenced by shutting down Mongo and watching the com.mongodb.ReplicaSetStatus$Node update Warning errors still appear in the app server logs

      2) when initializing Mongo with a server/port and not a List of ServerAddresses, calling Mongo.close() throws an error. This is in the context of my web container. I could not replicate it in a simple standalone java example.

      java.lang.NullPointerException at
      com.mongodb.DBTCPConnector.close(DBTCPConnector.java:352)
      at com.mongodb.Mongo.close(Mongo.java:297)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
      39)
      at
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
      25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at coldfusion.runtime.java.JavaProxy.invoke

            Assignee:
            eliot Eliot Horowitz (Inactive)
            Reporter:
            marcesher Marc Esher
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: