Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mutex behavior mismatch with MRI since JRuby 9.2.8.0 #5875

Open
walro opened this issue Sep 13, 2019 · 3 comments

Comments

@walro
Copy link

commented Sep 13, 2019

Environment

$ jruby -v
jruby 9.2.8.0 (2.5.3) 2019-08-12 a1ac7ff Java HotSpot(TM) 64-Bit Server VM 9.0.1+11 on 9.0.1+11 +jit [darwin-x86_64]

Expected Behavior

The following executes "forever" without errors on MRI 2.5.3 and JRuby 9.2.7.0:

mutex = Mutex.new

t1 = Thread.new do
  loop do
    mutex.synchronize do
      mutex.sleep 1 # not needed to provoke the error, but just to motivate the t1.run below
    end
  end
end

loop do
  mutex.synchronize do
  end

  t1.run
end

This is a real-world problem cooked down to its core. The real-world app (a busy web-app) uses https://github.com/sharpstone/rack-timeout, where one can find similar mutex usage.

Actual Behavior

$ jruby mutex.rb 
warning: thread "Ruby-0-Thread-1: mutex.rb:1" terminated with exception (report_on_exception is true):
ConcurrencyError: interrupted waiting for mutex
         lock at org/jruby/ext/thread/Mutex.java:101
  synchronize at org/jruby/ext/thread/Mutex.java:158
     mutex.rb at mutex.rb:5
         loop at org/jruby/RubyKernel.java:1425
     mutex.rb at mutex.rb:4
ThreadError: killed thread
    wakeup at org/jruby/RubyThread.java:1279
       run at org/jruby/RubyThread.java:1437
  mutex.rb at mutex.rb:15
      loop at org/jruby/RubyKernel.java:1425
    <main> at mutex.rb:11

After some digging around I would assume this is connected to the change in #5683. What I find a bit curious is that the main thread must also try to synchronize to force the error to happen.

@headius

This comment has been minimized.

Copy link
Member

commented Sep 16, 2019

I'm on it! The problem here is that for whatever reason I implemented mutex sleeping to sleep based on some arbitrary lock, rather than on the lock associated with the mutex.

@enebo enebo added this to the JRuby 9.2.9.0 milestone Sep 25, 2019
@mrmargolis

This comment has been minimized.

Copy link

commented Oct 4, 2019

Seeing this also happen in a Rails app that uses the message_bus gem on JRuby 9.2.8.0. Very similar trace to what @walro posted. Full blocker for being able to upgrade to 9.2.8.0 since we blow up inside the thread handling in that gem

@headius

This comment has been minimized.

Copy link
Member

commented Oct 16, 2019

Circled back to this. Will fix for 9.2.9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.