When trying to kick off Rack::Servers in different threads, I run into a bit of a weird race condition issue which only happens on Jruby-1.6.7. It seems that the Rack::Server#start calls a trap(:INT) which invokes Kernel#trap to call __jtrap in Jruby land. Only I get a NoMethodError when the RubyKernel#trap calls __jtrap.
I've got a test here which can reproduce (on both linux and OSX) using jdk1.6. Testing in jruby-1.7.0-preview seems to work.
Here is the offending java code RubyKernel#trap.
Simply retrying will eventually 'work' and __jtrap can be found it seems, but retrying until it works seems incorrect. A simple global lock cannot work in this situation as Rack::Server#start doesn't return to return the hold on the lock until end.
Speculating that the __jtrap method hasn't been loaded, so the first thread goes to load, second sees it's loaded and tries to use (and fails).
# Do other threaded trap
before the threads are created seems to alleviate the issue.
This code was rewritten and moved mostly into Ruby for JRuby 1.7.0. The given script works fine now.