History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: JRUBY-1559
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Critical Critical
Assignee: Charles Oliver Nutter
Reporter: Micah Alles
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
JRuby

JavaObject.wrap synchronizing on the java instance can cause deadlock

Created: 12/Nov/07 11:04 AM   Updated: 10/Sep/08 06:51 PM
Component/s: Java Integration
Affects Version/s: JRuby 1.0.0, JRuby 1.0.1, JRuby 1.1b1, JRuby 1.0.2
Fix Version/s: JRuby 1.1

Time Tracking:
Not Specified

File Attachments: 1. File deadlock.tgz (4 kb)
2. File java_object_wrap_locking.diff (0.9 kb)

Environment:
OS X Leopard / Tiger
Windows Vista / XP / 2000
Linux
Java 1.5.x and 1.6.x
JRuby 1.0, 1.0.1, 1.0.2, 1.1b and edge

Testcase included: yes
Patch Submitted: Yes


 Description  « Hide
In JavaObject.wrap(...) a RubyObject is created which corresponds to an instance of a java object. The java instance is currently used to synchronize access to the cached RubyObjects.

Synchronizing on the java instance can be inherently dangerous due to the common practice in java of declaring public methods synchronized and using non-private instances for synchronized blocks.

This problem has affected our development of a desktop application when using the Batik library through jruby. One of the classes which is a part of their public API followed the practice described above of using publicly available objects as a monitor for synchronization. The combination of that practice and the way JavaObject.wrap was locking on the same java instance caused periodic deadlock in our application.

I've included a patch and a small sample project with a test case which results in deadlock with the current JavaObject.wrap implementation and successfully runs to completion with the patch applied. The patch synchronizes on the JavaObject wrapper instance instead of the java instance.

To run the test from within the included project:
rake test jruby=path/to/jruby



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Bill Dortch - 12/Nov/07 11:37 AM
I have a fix in the works for JRUBY-199 (and related) that eliminates this synchronization, among other things. (It actually eliminates the cache in question, replacing it elsewhere with a cache of proxy instances. See my old note from 28 June at JRUBY-199; I'm pretty much following the scheme I laid out there.) Will get this in in the next day or so.

Micah Alles - 12/Nov/07 12:28 PM
Oops, I meant to say JavaObject instead of RubyObject in the description for this issue. I couldn't find a way to modify the description. If someone has a moment and the ability correct the post, please do.

Bill,

Are there any further planned releases of the 1.0.x branch which this could be applied to? I look forward to seeing your fix! We're having to hand patch new versions of JRuby at the moment, as this is a stopper for us.

Thanks!


Charles Oliver Nutter - 26/Aug/08 02:48 AM
Fixing the description as Micah recommended...I think.

Charles Oliver Nutter - 26/Aug/08 03:13 AM
I'm marking this as fixed in 1.1, since I believe some time earlier Bill added his new ObjectProxyCache, which handles these sticky synchronization issues much better. The provided test case passes ok...I'm trying to adapt it into our test suite.