From: Yehuda Katz Date: 2011-11-13T05:43:47+09:00 Subject: [ruby-core:40972] Re: [Backport93 - Backport #5621] Please backport thread-safe autoloading patch --001636499b6b7ec58404b18fb111 Content-Type: text/plain; charset=ISO-8859-1 Unfortunately ruby-head has a deadlock in one of my go-to scenarios for this feature. # foo.rb class Foo sleep 2 def self.shared_attributes %w(some list) end include Bar end # bar.rb sleep 1 module Bar attr_accessor *Foo.shared_attributes end # test.rb autoload :Foo, "./foo" autoload :Bar, "./bar" t1 = Thread.new { Foo } t2 = Thread.new { Bar } t1.join t2.join ## RUBY 1.9.3 OUTPUT ## /Users/wycats/Code/tmp/test_autoload/bar.rb:6:in `': undefined method `shared_attributes' for Foo:Class (NoMethodError) from /Users/wycats/Code/tmp/test_autoload/bar.rb:5:in `' from test_autoload.rb:5:in `block in
' ## RUBY 1.9.4 OUTPUT ## test_autoload.rb:7:in `join': deadlock detected (fatal) from test_autoload.rb:7:in `
' Yehuda Katz (ph) 718.877.1325 On Sat, Nov 12, 2011 at 8:58 AM, Mike Perham wrote: > > Issue #5621 has been updated by Mike Perham. > > > My use case: I want to use Rails in thread-safe mode in production so I > don't have to fork 20 Ruby processes to handle 20 concurrent requests. > When developing, Rails auto loads classes on every request. This auto > loading is critical to Rails' rapid development cycle and there's no way > I'm going to disable it. Unfortunately the current autoload behavior makes > the development environment incompatible with thread-safe mode. > > Since no developer wants to lose the rapid development cycle and no > developer is crazy enough to run a very different configuration in > production than development (going from non-thread-safe to thread-safe > between dev and prod is a huge change), no one currently uses thread-safe > mode. > > I will try trunk in a few days and report back if it solves the problem. > ---------------------------------------- > Backport #5621: Please backport thread-safe autoloading patch > http://redmine.ruby-lang.org/issues/5621 > > Author: Mike Perham > Status: Open > Priority: Normal > Assignee: > Category: > Target version: > > > This is critical to using Rails in thread-safe mode. JRuby is supposed to > have it in the next release, 1.7. > > http://redmine.ruby-lang.org/issues/921 > > Waiting another 12-18 months for 1.9.4 to come out would really suck. > > > -- > http://redmine.ruby-lang.org > > --001636499b6b7ec58404b18fb111 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Unfortunately ruby-head has a deadlock in one of my go-to scenarios fo= r this feature.

# foo.rb
class Foo<= /div>
=A0 sleep 2

=A0 def self.shared_attribut= es
=A0 =A0 %w(some list)
=A0 end

=A0 i= nclude Bar
end

# bar.rb
=
sleep 1

module Bar
=A0 attr_accesso= r *Foo.shared_attributes
end

# test.rb
autoload := Foo, "./foo"
autoload :Bar, "./bar"

t1 =3D Thread.new { Foo }
t2 =3D Thread.new { Bar= }

t1.join
t2.join

## RUBY 1.9.3 OUTPUT ##
/Users/wycats/Code/tmp/test_autolo= ad/bar.rb:6:in `<module:Bar>': undefined method `shared_attribute= s' for Foo:Class (NoMethodError)
from = /Users/wycats/Code/tmp/test_autoload/bar.rb:5:in `<top (required)>= 9;
from test_autoload.rb:5:in `block in <main>'

## RUBY 1.9.4 OUTPUT ##
test_= autoload.rb:7:in `join': deadlock detected (fatal)
from test_autoload.r= b:7:in `<main>'


Yehuda Katz
(ph) 718.877.132= 5


On Sat, Nov 12, 2011 at 8:58 AM, Mike Pe= rham <mperham@gma= il.com> wrote:

Issue #5621 has been updated by Mike Perham.


My use case: I want to use Rails in thread-safe mode in production so I don= 't have to fork 20 Ruby processes to handle 20 concurrent requests. =A0= When developing, Rails auto loads classes on every request. =A0This auto lo= ading is critical to Rails' rapid development cycle and there's no = way I'm going to disable it. =A0Unfortunately the current autoload beha= vior makes the development environment incompatible with thread-safe mode.<= br>
Since no developer wants to lose the rapid development cycle and no develop= er is crazy enough to run a very different configuration in production than= development (going from non-thread-safe to thread-safe between dev and pro= d is a huge change), no one currently uses thread-safe mode.

I will try trunk in a few days and report back if it solves the problem.
-----------------------------------= -----
Backport #5621: Please backport thread-safe autoloading patch
http= ://redmine.ruby-lang.org/issues/5621

Author: Mike Perham
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


This is critical to using Rails in thread-safe mode. =A0JRuby is supposed t= o have it in the next release, 1.7.

http:= //redmine.ruby-lang.org/issues/921

Waiting another 12-18 months for 1.9.4 to come out would really suck.


--
http://redmine.r= uby-lang.org


--001636499b6b7ec58404b18fb111--