Issue Details (XML | Word | Printable)

Key: JRUBY_RACK-4
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Critical Critical
Assignee: Unassigned
Reporter: jdmorani
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
jruby-rack

Thread safety issue with JRuby-Rack due to non synchronized RubyIO objects

Created: 18/Apr/09 07:39 PM   Updated: 21/Apr/09 03:05 AM   Resolved: 20/Apr/09 03:09 PM
Component/s: None
Affects Version/s: None
Fix Version/s: 0.9.5

Time Tracking:
Not Specified

Environment:

All


Tags:


 Description  « Hide

When calling a servlet with more than 2 threads, ocassionaly io#read returns an empty string. After further investigation, we determined that to_io is returning the same IO objects to multiple ruby threads. Therefore once one thread read the content of the IO, the second thread reading the shared IO gets an empty string back.

The problem is located @ $jruby-rack_home/src/main/java/org/jruby/rack/DefaultRackApplication.java

Headius suggested to define the method "to_io" with getSingletonClass() instead of getMetaClass().
After following headius recommendation, the problem went away.



headius added a comment - 18/Apr/09 07:43 PM

The getSingletonClass change is probably the simplest option, but I think we should consider defining the to_io method once and having it access either a field on RackEnvironment or an instance variable on the ruby side. Redefining the method every time will cost, as will having all requests execute against a new singletonized object.


Nick Sieger added a comment - 20/Apr/09 03:09 PM

Can you try the fix in 057f8061039abd9b5228f83be19e8fb97033cd71:

http://kenai.com/projects/jruby-rack/sources/main/revision/057f8061039abd9b5228f83be19e8fb97033cd71


jdmorani added a comment - 21/Apr/09 03:05 AM

I confirm that it fixes the problem.
Thanks a lot Nick for the quick turnaround.
Jean-Do