threadContextMap leaks RubyThread on death of adopted thread
------------------------------------------------------------
Key: JRUBY-4264
URL: http://jira.codehaus.org/browse/JRUBY-4264
Project: JRuby
Issue Type: Bug
Affects Versions: JRuby 1.4
Environment: Java HotSpot(TM) 64-Bit Server VM, Version 1.6.0_12
Reporter: Chris Andrews
Assignee: Thomas E Enebo
Attachments: Harness.java
We have an app which handles received messages from ActiveMQ in Ruby, as part
of a Rails app running inside Glassfish. This means that we have threads
started by the ActiveMQ client executing inside JRuby, so they get adopted and
then die off some time later having handled a number of messages.
It looks like a RubyThread and its ThreadContext are leaked at the death of an
adopted thread, since the cleanup in RubyRunnable isn't called, and despite the
use of WeakHashMaps in ThreadService it can't be GC'd:
this.rubyThreadMap = Collections.synchronizedMap(newWeakHashMap<Object,
RubyThread>());
this.threadContextMap =
Collections.synchronizedMap(newWeakHashMap<RubyThread,ThreadContext>());
When the adopted thread dies, its entry in rubyThreadMap is removed, but the
corresponding entry in threadContextMap is not. This seems to be because
there's a strong reference from ThreadContext back to RubyThread - the
WeakHashMap is only weak towards its keys, and so the entry is leaked.
It helps to forcibly reap these leaked entries based on the fact the
RubyThreads no longer have a live Thread, using a daemon thread to regularly
iterate the threadContextMap.
I'm attaching a program which demonstrates the issue we're seeing outside of a
webapp container.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email