Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.6.7, JRuby 1.7.0.pre1
-
Fix Version/s: JRuby 1.6.8, JRuby 1.7.0.pre1
-
Component/s: Core Classes/Modules
-
Labels:None
-
Number of attachments :
Description
While fixing JRUBY-6522, I found that there are a few additional places where we have static ThreadLocals that can cause ClassLoader leaks in environments where a pool of threads may encounter multiple JRuby runtimes, such as when applications are redeployed to a webapp server.
I audited for static threadlocals, and found the following:
org.jruby.ext.ffi.AutoPointer:25
private static final ThreadLocal<ReaperGroup> currentReaper = new ThreadLocal<ReaperGroup>();
org.jruby.ext.ffi.jffi.AllocatedNativeMemoryIO:14
private static final ThreadLocal<AllocationGroup> currentBucket = new ThreadLocal<AllocationGroup>();
org.jruby.ext.ffi.jffi.TransientNativeMemoryIO:43
private static final ThreadLocal<Magazine> currentMagazine = new ThreadLocal<Magazine>();
org.jruby.interpreter.IRBreakJump:13
private static ThreadLocal<IRBreakJump> threadLocalBJ = new ThreadLocal<IRBreakJump>() {
public IRBreakJump initialValue() { return new IRBreakJump(); }
};
org.jruby.interpreter.IRReturnJump:11
private static ThreadLocal<IRReturnJump> threadLocalRJ = new ThreadLocal<IRReturnJump>() {
public IRReturnJump initialValue() { return new IRReturnJump(); }
};
There's also this in org.jruby.Ruby, but I'm not sure if it's a risk; it's explicitly used for thread-local stuff, but via an API we don't publish or recommend. Perhaps it should be removed?
private static ThreadLocal<Ruby> threadLocalRuntime = new ThreadLocal<Ruby>();
I fixed the FFI ones in commit a0decb7e151103f802db72cad5ba380c59eefd60