[JAVA-191]  Possible leak in Java 2.2 Driver with ReplicaSetStatus$Updater Created: 15/Oct/10  Updated: 29/Oct/10  Resolved: 27/Oct/10

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: 2.2
Fix Version/s: 2.3

Type: Bug Priority: Major - P3
Reporter: Marc Esher Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

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



 Comments   
Comment by auto [ 27/Oct/10 ]

Author:

{'login': 'erh', 'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}

Message: fix potential memory leak JAVA-191
http://github.com/mongodb/mongo-java-driver/commit/d55d9919cc2cc90a69d97091a816eb0b195b762f

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