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

Java exception escaping exiting a monitor that hasn't been entered #2922

Closed
nirvdrum opened this issue Mar 10, 2023 · 1 comment
Closed

Java exception escaping exiting a monitor that hasn't been entered #2922

nirvdrum opened this issue Mar 10, 2023 · 1 comment
Assignees

Comments

@nirvdrum
Copy link
Collaborator

nirvdrum commented Mar 10, 2023

I'm working on refreshing our tags for the MRI tests. While doing so, I ran into a situation where a Java exception is escaping into Ruby when exiting a Monitor incorrectly.

The following code should raise a ThreadError, but instead we're triggering a ShouldNotReachHere exception.

require 'monitor'

m = Monitor.new
m.exit

On MRI, we see the ThreadError we expect:

> ruby -v bad-monitor.rb
ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [arm64-darwin22]
bad-monitor.rb:4:in `exit': current fiber not owner (ThreadError)
        from bad-monitor.rb:4:in `<main>'

On TruffleRuby we end up an escaped Java exception.

> jt ruby -v bad-monitor.rb
truffleruby 23.0.0-dev-671182fb*, like ruby 3.1.3, GraalVM CE JVM [aarch64-darwin]

truffleruby: an internal exception escaped out of the interpreter,
please report it to https://github.com/oracle/truffleruby/issues.

the lock was not held when calling unlockInternal() (com.oracle.truffle.api.CompilerDirectives.ShouldNotReachHere)
        from com.oracle.truffle.api.CompilerDirectives.shouldNotReachHere(CompilerDirectives.java:574)
        from com.oracle.truffle.api.CompilerDirectives.shouldNotReachHere(CompilerDirectives.java:520)
        from org.truffleruby.core.mutex.MutexOperations.unlockInternal(MutexOperations.java:112)
        from org.truffleruby.core.mutex.MutexOperations.unlock(MutexOperations.java:105)
        from org.truffleruby.core.monitor.TruffleMonitorNodes$MonitorExit.exit(TruffleMonitorNodes.java:83)
        from org.truffleruby.core.monitor.TruffleMonitorNodesFactory$MonitorExitFactory$MonitorExitNodeGen.executeAndSpecialize(TruffleMonitorNodesFactory.java:476)
        from org.truffleruby.core.monitor.TruffleMonitorNodesFactory$MonitorExitFactory$MonitorExitNodeGen.execute(TruffleMonitorNodesFactory.java:467)
        from org.truffleruby.language.control.SequenceNode.execute(SequenceNode.java:37)
        from org.truffleruby.language.RubyMethodRootNode.execute(RubyMethodRootNode.java:65)
/Users/nirvdrum/dev/workspaces/truffleruby-ws/graal/sdk/mxbuild/darwin-aarch64/GRAALVM_A33290E019_JAVA17/graalvm-a33290e019-java17-23.0.0-dev/Contents/Home/languages/ruby/lib/mri/monitor.rb:194:in `mon_exit'
        from bad-monitor.rb:4:in `<main>'
@andrykonchin andrykonchin self-assigned this Mar 20, 2023
@andrykonchin
Copy link
Member

Fixed in b6c6096

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants