JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-6621

New ThreadLocal recursiveKey breaks usage of runtimes across multiple Java threads

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.7.0.pre1
    • Fix Version/s: JRuby 1.7.0.pre1
    • Component/s: None
    • Labels:
      None
    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      As of commit 46c59ad659136fbda7c7fcd77b8bb47180f424f0 you can no longer use a JRuby runtime across multiple Java threads when using 1.9 mode because the ThreadLocal variable recursiveKey only gets initialized once when the runtime is initialized. So, as soon as I pass an initialzed runtime to a new thread recursiveKey has no value and results in an NPE like:

      java.lang.NullPointerException
      at org.jruby.RubyHash.internalGetEntry(RubyHash.java:506) [jruby.jar:]
      at org.jruby.RubyHash.internalGet(RubyHash.java:502) [jruby.jar:]
      at org.jruby.RubyHash.fastARef(RubyHash.java:942) [jruby.jar:]
      at org.jruby.Ruby.recursiveCheck(Ruby.java:3765) [jruby.jar:]
      at org.jruby.Ruby.execRecursiveInternal(Ruby.java:3801) [jruby.jar:]
      at org.jruby.Ruby.execRecursiveOuter(Ruby.java:3876) [jruby.jar:]
      at org.jruby.RubyArray.hash19(RubyArray.java:694) [jruby.jar:]\

      JUnit TestCase at https://gist.github.com/2494050

        Issue Links

          Activity

          Hide
          Ben Browning added a comment -

          Pull request with fix and testcase at https://github.com/jruby/jruby/pull/144

          Show
          Ben Browning added a comment - Pull request with fix and testcase at https://github.com/jruby/jruby/pull/144
          Hide
          Charles Oliver Nutter added a comment -

          Merged to master in 466335e. Thanks!

          Show
          Charles Oliver Nutter added a comment - Merged to master in 466335e. Thanks!
          Hide
          Ben Browning added a comment -

          I just realized that I was running my new test manually and the JRuby JUnit tests don't automatically pick up all tests, instead preferring TestSuites. So, to get run by CI, this test needs to be added to MainTestSuite or similar I believe. Sorry about not catching that.

          Show
          Ben Browning added a comment - I just realized that I was running my new test manually and the JRuby JUnit tests don't automatically pick up all tests, instead preferring TestSuites. So, to get run by CI, this test needs to be added to MainTestSuite or similar I believe. Sorry about not catching that.
          Hide
          Charles Oliver Nutter added a comment -

          Ahh yes.

          Actually I will add this to our regression specs, which we use for individual regression failures we want to keep in their own suite (and which are usually rather JRuby-specific. (spec/regression)

          Thanks again for the fix and test

          Show
          Charles Oliver Nutter added a comment - Ahh yes. Actually I will add this to our regression specs, which we use for individual regression failures we want to keep in their own suite (and which are usually rather JRuby-specific. (spec/regression) Thanks again for the fix and test
          Hide
          Charles Oliver Nutter added a comment -

          Oh, actually, this was a test written in Java, which makes more sense. I'll add it to the appropriate place.

          Show
          Charles Oliver Nutter added a comment - Oh, actually, this was a test written in Java, which makes more sense. I'll add it to the appropriate place.
          Hide
          Ben Browning added a comment -

          Yep - I first tried to write the test in Ruby under spec/regression but I couldn't figure out how to reproduce the failure from within Ruby, even when creating a new runtime inside Ruby and spawning java.lang.Threads inside Ruby. Hence I punted and went to Java.

          Show
          Ben Browning added a comment - Yep - I first tried to write the test in Ruby under spec/regression but I couldn't figure out how to reproduce the failure from within Ruby, even when creating a new runtime inside Ruby and spawning java.lang.Threads inside Ruby. Hence I punted and went to Java.

            People

            • Assignee:
              Charles Oliver Nutter
              Reporter:
              Ben Browning
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: