FULL PRODUCT VERSION :
java version "1.6.0_16"
Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
Java HotSpot(TM) 64-Bit Server VM (build 14.2-b01, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux cicada 2.6.18-92.el5 #1 SMP Tue Apr 29 13:16:15 EDT 2008 x86_64 x86_64 x86_64 GNU/Linux
EXTRA RELEVANT SYSTEM CONFIGURATION :
Must run Java security manager to trigger issue. Even a simple policy file with a single grant { java.security.AllPermission; }; will suffice.
A DESCRIPTION OF THE PROBLEM :
SSLSessionImpl contains a Hashtable for session-specific data. The key for this table is the SecureKey class (contained in the same file), and when the security manager is enabled, it uses an AccessControlContext as part of this key.
When running in a servlet container (or perhaps always?) the AccessControlContext is always different, so putting a value into this session cannot subsequently be retrieved. Programs that attempt to retrieve cached information from the session get null, recalculate, and attempt to re-persist into the cache. When this is done frequently, it can create huge memory leaks in an application. This is exacerbated by the 24-hour default session timeout.
Encountered this bug by deploying a CXF web service into an Apache Tomcat container. CXF requests certain JSSE properties from the request, and Tomcat attempts to cache them in the session. I submitted a patch to Tomcat that employs the workaround I described in the Workaround field. Tomcat bug report: https://issues.apache.org/bugzilla/show_bug.cgi?id=47744
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Enable the Java Security Manager. Even the simplest possible policy file will be satisfactory for reproducing this bug.
Attach a memory profiler to the JVM.
During an SSL session, retrieve the SSLSession object. Continuously put a large object into the session using the same key. Note that calling getValue with the same key returns null.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Memory usage is constant no matter how many calls to putValue are made.
getValue returns the object that is placed into the session.
ACTUAL -
getValue returns null; memory usage increases with every call to putValue.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
N/A. OutOfMemory if allowed to continue for a long time.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
// this bug requires a client-server test harness to duplicate.
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use a WeakHashMap that takes an SSLSession as a key instead of using the SSL session's attribute store.