Open randallt opened 4 years ago
@randallt would you like to submit PR? please add comments to the code.
Can someone please submit the PR for me? The only non-standard thing about the equals method is the trick to call the equals method on 'obj', which gets through the Proxy and WrapperProxy layers so that one of the other comparisons can function.
@randallt could you test https://github.com/opentracing-contrib/java-jdbc/pull/97
I am using a custom fork of the Java Special Agent. We have a service that relies on the Quartz scheduler, which uses c3p0 (v0.9.1.1). With the tracing agent applied, the service leaks memory until it throws an OOM error.
A heap dump showed that TracingPreparedStatements were being leaked. I tracked this to the use of the WrapperProxy and the fact that, given a Proxy instance of TracingConnection or TracingStatement, a call to obj.equals(obj) will always return false. This is because the WrapperProxy is delegating all method calls to the wrapper or the original object, but these don't know how to handle the added Proxy/WrapperProxy layers for the equals method. This leads to c3p0 not being able to clean up its collections for the connections/statements.
I was able to fix this by adding a custom equals method to TracingStatement:
and to TracingConnection:
These may not be 100% hardened, but they got me past the memory leak with c3p0. I thought I should be a good citizen and open an issue regarding this.