Cannot make rack load the proper rails code in threadsafe mode

Hi Buddies,

I am currently working on getting a spree project online by JRuby on
Rails. I am using Spree 0.11, Rails 2.3.8 and JRuby 1.5.3.
I also write quite a couple of extensions to meet our business for
spree and freeze the spree code in my source code at ${project}/vendor/
spree.

And I deployed it in Tomcat 6, it works well without the thread safe
feature.

For JRuby consume huge memory, I wanted to take the advantage of the
thread-safe ability of rails since Rails 2.3.8. So I add
config.threadsafe! in the production.rb and take the site online.

But I will get the following error which would not happen without the
config.threadsafe! line.

It looks like that while the request going directly through the metal
rack code, create_admin_user.rb, it could not find the User::Role.

Is there anything specific I should take care to get this work?

Oct 10, 2010 12:31:21 AM org.apache.catalina.core.ApplicationContext
log
INFO: /!\ FAILSAFE /!\ Sun Oct 10 00:31:21 +0800 2010
Status: 500 Internal Server Error
uninitialized constant User::Role
/Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/
tomcat/webapps/ROOT/WEB-INF/vendor/rails/activesupport/lib/
active_support/dependencies.rb:105:in const_missing' /Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/ tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/ active_record/base.rb:1:inclass_eval’
/Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/
tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/
active_record/base.rb:2234:in compute_type' /Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/ tomcat/webapps/ROOT/WEB-INF/vendor/rails/activesupport/lib/ active_support/core_ext/kernel/reporting.rb:11:insilence_warnings’
/Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/
tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/
active_record/base.rb:2230:in compute_type' /Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/ tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/ active_record/reflection.rb:156:inklass’
/Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/
tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/
active_record/associations.rb:2045:in initialize' /Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/ tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/ active_record/associations.rb:1929:innew’
/Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/
tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/
active_record/associations.rb:1929:in build_join_association' /Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/ tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/ active_record/associations.rb:1912:inbuild’
/Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/
tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/
active_record/associations.rb:1915:in build' /Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/ tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/ active_record/associations.rb:1914:ineach’
/Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/
tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/
active_record/associations.rb:1914:in build' /Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/ tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/ active_record/associations.rb:1835:ininitialize’
/Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/
tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/
active_record/associations.rb:1400:in new' /Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/ tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/ active_record/associations.rb:1400:infind_with_associations’
/Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/
tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/
active_record/associations.rb:1399:in catch' /Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/ tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/ active_record/associations.rb:1399:infind_with_associations’
/Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/
tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/
active_record/base.rb:1576:in find_every' /Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/ tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/ active_record/base.rb:1535:infind_initial’
/Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/
tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/
active_record/base.rb:616:in find' /Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/ tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/ active_record/base.rb:626:infirst’
/Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/
tomcat/webapps/ROOT/WEB-INF/vendor/spree/app/metal/
create_admin_user.rb:11:in call' /Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/ tomcat/webapps/ROOT/WEB-INF/vendor/rails/railties/lib/rails/rack/ metal.rb:44:incall’
/Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/
tomcat/webapps/ROOT/WEB-INF/vendor/rails/railties/lib/rails/rack/
metal.rb:43:in each' /Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/ tomcat/webapps/ROOT/WEB-INF/vendor/rails/railties/lib/rails/rack/ metal.rb:43:incall’
/Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/
tomcat/webapps/ROOT/WEB-INF/vendor/rails/actionpack/lib/
action_controller/session/abstract_store.rb:128:in call' /Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/ tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/ active_record/query_cache.rb:29:incall’
/Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/
tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/
active_record/connection_adapters/abstract/query_cache.rb:34:in
cache' /Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/ tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/ active_record/query_cache.rb:9:incache’
/Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/
tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/
active_record/query_cache.rb:28:in call' /Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/ tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/ active_record/connection_adapters/abstract/connection_pool.rb:361:incall’
/Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/
tomcat/webapps/ROOT/WEB-INF/vendor/rails/actionpack/lib/
action_controller/failsafe.rb:26:in call' /Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/ tomcat/webapps/ROOT/WEB-INF/vendor/rails/actionpack/lib/ action_controller/dispatcher.rb:106:incall’
file:/Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/
tomcat/webapps/ROOT/WEB-INF/lib/jruby-rack-1.0.1.jar!/rack/adapter/
rails.rb:36:in serve_rails' file:/Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/ tomcat/webapps/ROOT/WEB-INF/lib/jruby-rack-1.0.1.jar!/rack/adapter/ rails.rb:41:incall’
file:/Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/
tomcat/webapps/ROOT/WEB-INF/lib/jruby-rack-1.0.1.jar!/jruby/rack/
rails.rb:180:in call' file:/Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/ tomcat/webapps/ROOT/WEB-INF/lib/jruby-rack-1.0.1.jar!/rack/handler/ servlet.rb:19:incall’
:1

Best wishes,
Stanley Xu

My best guess is that Spree has not been actively developed with the
“threadsafe!” option turned on, and as a result there is some code
that is assumed to be lazy-loaded that should be changed to be
eager-loaded. I’d suggest editing /app/metal/
create_admin_user.rb to require ‘user/role’ up front or possibly
adding a config/initializers/eager_load.rb where you run these
necessary requires when in production/threadsafe mode.

/Nick

On Sat, Oct 9, 2010 at 9:19 PM, Stanley Xu [email protected] wrote:

Is there anything specific I should take care to get this work?
tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/
/Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/
active_record/associations.rb:1929:in build_join_association' tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/ /Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/ active_record/base.rb:1535:infind_initial’
tomcat/webapps/ROOT/WEB-INF/vendor/rails/railties/lib/rails/rack/
/Users/stanley/Documents/codebase/imoso_code/lianyijia_tomcat/
tomcat/webapps/ROOT/WEB-INF/vendor/rails/activerecord/lib/
action_controller/dispatcher.rb:106:in call' tomcat/webapps/ROOT/WEB-INF/lib/jruby-rack-1.0.1.jar!/rack/handler/ servlet.rb:19:incall’
:1

Best wishes,
Stanley Xu


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs