Re: useCompression=true and potential Memory leak due to connection tracking via CompressionInputStreamMemoryLeak
Posted by: Dominic Tootell
Date: May 13, 2013 07:56AM

Hi Alexander

Some additional information to my last post. I applied the proposed patch to null out the Connection strong reference within the close() method of CompressionInputStream locally, and adapted my Test case to comment out the Connection.close() method:

// if(connection!=null) connection.close();
// }catch(Exception e){}

The result is the following:

"Data source rejected establishment of connection, message from server: too many connections".

The reason for this is that the AbandonedConnectionCleanupThread isn't recieving the the ConnectionPhantomReference from the ReferenceQueue, as the CompressedInputStream is keeping the object alive; and therefore the JVM isn't queuing the object for GC. The result is that the AbandonedConnectionCleanupThread isn't tracking the connection and does not call close() on the connection on behalf of the bad application that isn't closing the connection. If I change the local mysql server to accept more connections, I hit the OOM.

With the WeakReference in place on the CompressedInputStream, both the cases of the client app using connection.close() and the client app behaving badly (just nulling out the connection reference) are caught; and the OOM or connection issue isn't seen; with the AbandonedConnectionCleanupThread doing the job of tracking the connection.

Let me know if you need more information.


Options: ReplyQuote

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.