Ruby's `File.exist?` ThreadError - ruby-on-rails

I am encountering errors when I am using Ruby's File.exist? method in middleware. I have no idea why.
This is the background. I am improving some old webapp which hosts around 100GB of photos and growing. I need to replicate production environment on my computer, but I don't want to download all those files. It would be great if app could check if given file exists in my filesystem and either serve it or redirect to production server.
I thought I could do simple rack app as middleware:
require 'rack/utils'
class FetchMissingPicturesMiddleware
def initialize(app)
#app = app
end
def call(env)
if env["PATH_INFO"].starts_with? "/system/attachments/" && !File.exist?(Rails.root.join('public').join(env["PATH_INFO"][1..-1]))
[307, { "Location" => "http://production.example.com" + env["PATH_INFO"] }, ""]
else
#app.call(env)
end
end
end
However, following error is thrown (not always, for some pictures it just works):
[2012-11-26 14:28:12] ERROR ThreadError: thread 0x10aed55e8 tried to join itself
/Users/skale/.rvm/gems/ruby-1.8.7-p371/gems/actionpack-2.3.9/lib/action_controller/reloader.rb:31:in `lock'
/Users/skale/.rvm/gems/ruby-1.8.7-p371/gems/actionpack-2.3.9/lib/action_controller/reloader.rb:31:in `run'
/Users/skale/.rvm/gems/ruby-1.8.7-p371/gems/actionpack-2.3.9/lib/action_controller/dispatcher.rb:108:in `call'
/Users/skale/.rvm/gems/ruby-1.8.7-p371/gems/rails-2.3.9/lib/rails/rack/static.rb:31:in `call'
/Users/skale/.rvm/gems/ruby-1.8.7-p371/gems/rack-1.1.3/lib/rack/urlmap.rb:47:in `call'
/Users/skale/.rvm/gems/ruby-1.8.7-p371/gems/rack-1.1.3/lib/rack/urlmap.rb:41:in `each'
/Users/skale/.rvm/gems/ruby-1.8.7-p371/gems/rack-1.1.3/lib/rack/urlmap.rb:41:in `call'
/Users/skale/.rvm/gems/ruby-1.8.7-p371/gems/rails-2.3.9/lib/rails/rack/log_tailer.rb:17:in `call'
/Users/skale/.rvm/gems/ruby-1.8.7-p371/gems/rack-1.1.3/lib/rack/content_length.rb:13:in `call'
/Users/skale/.rvm/gems/ruby-1.8.7-p371/gems/rack-1.1.3/lib/rack/handler/webrick.rb:48:in `service'
/Users/skale/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/Users/skale/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/Users/skale/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/Users/skale/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:162:in `start'
/Users/skale/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/Users/skale/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:95:in `start'
/Users/skale/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:92:in `each'
/Users/skale/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:92:in `start'
/Users/skale/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:23:in `start'
/Users/skale/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/webrick/server.rb:82:in `start'
/Users/skale/.rvm/gems/ruby-1.8.7-p371/gems/rack-1.1.3/lib/rack/handler/webrick.rb:14:in `run'
/Users/skale/.rvm/gems/ruby-1.8.7-p371/gems/rails-2.3.9/lib/commands/server.rb:111
script/server:6:in `require'
script/server:6
I am surprised with this issue because it's run inside mutex provided by Rack::Lock. Moving this middleware before Rack::Lock does not help. After removing File.exist? errors are gone. This is Ruby 1.8.7 with freshest (1.8.24) rubygems on Rails 2.3.9.
Thanks for your help.

Actually, the problem was bit different. The last element of the response array should be an array too.
wrong:
[307, { "Location" => "http://production.example.com" + env["PATH_INFO"] }, ""]
good:
[307, { "Location" => "http://production.example.com" + env["PATH_INFO"] }, []]

Related

Rails: Fedena webpage has a redirect loop error. No method error undefined method config_value for nil:NilClass

i have installed fedena (rails application) in my website
http://www.technoadmin.com/
i have installed all plugins, gems, created and migrated the db.
i have created the symbolic link like this
ln -s ~/fedena/public ~/public_html
when visiting my webpage it shows
This webpage has a redirect loop
so please help me. i am a newbie.i have tried to install this
application for the last
one month. i think i have reached the final step. so please help me to
solve this error.i will be very thankful to you.
and my production logfile is
# Logfile created on Fri Jul 26 14:55:03 +0530 2013
Processing UserController#login (for 182.73.241.18 at 2013-07-26 15:00:48) [GET]
Parameters: {"action"=>"login", "controller"=>"user"}
[FedenaRescue] No method error undefined method `config_value' for nil:NilClass
NoMethodError (undefined method `config_value' for nil:NilClass):
app/controllers/application_controller.rb:319:in `set_user_language'
vendor/bundle/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:178:in `send'
vendor/bundle/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:178:in `evaluate_method'
vendor/bundle/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:166:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:225:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:629:in `run_before_filters'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:615:in `call_filters'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/rescue.rb:160:in `perform_action_without_flash'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/flash.rb:146:in `perform_action'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:532:in `send'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:532:in `process_without_filters'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:606:in `process'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:391:in `process'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:386:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:437:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:87:in `dispatch'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:121:in `_call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:130:in `build_middleware_stack'
vendor/bundle/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:29:in `call'
vendor/bundle/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:29:in `call'
vendor/bundle/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache'
vendor/bundle/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:9:in `cache'
vendor/bundle/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:28:in `call'
vendor/bundle/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/string_coercion.rb:25:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/params_parser.rb:15:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/session/cookie_store.rb:93:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/failsafe.rb:26:in `call'
vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:106:in `call'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_request_handler.rb:513:in `accept_and_process_next_request'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/classic_rails/application_spawner.rb:321:in `start_request_handler'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/classic_rails/application_spawner.rb:275:in `send'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/classic_rails/application_spawner.rb:275:in `handle_spawn_application'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/utils.rb:479:in `safe_fork'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/classic_rails/application_spawner.rb:270:in `handle_spawn_application'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:357:in `__send__'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:180:in `start'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/classic_rails/application_spawner.rb:149:in `start'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb:219:in `spawn_rails_application'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb:214:in `spawn_rails_application'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server_collection.rb:82:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb:213:in `spawn_rails_application'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb:132:in `spawn_application'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:357:in `__send__'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.9/helper-scripts/passenger-spawn-server:99
Redirected to http://technoadmin.com/user/dashboard
These are the lines from 310 to 325 and i have only 325 lines in my application_controller.rb
return #local_tzone_time
end
private
def set_user_language
lan = Configuration.find_by_config_key("Locale")
I18n.default_locale = :en
Translator.fallback(true)
if session[:language].nil?
I18n.locale = lan.config_value
else
I18n.locale = session[:language]
end
News.new.reload_news_bar
end
end
the problem is with a method called config_value
NoMethodError (undefined method config_value' for nil:NilClass): app/controllers/application_controller.rb:319:inset_user_language'
so check your application_controller.rb on line 319 and post what's there
EDIT:
in your code (line 319), you're calling config_value on lan - but the error message is saying that lan has a nil value - so config_value can't be called on it.
earlier you have lan = Configuration.find_by_config_key("Locale") - so i'm guessing that rails can't find a config_key called "Locale" - but really I'm not sure. Did you write this code or was it generated by a gem?
I had this same issue when trying to setup Fedena on Ubuntu 20.04 using Docker.
Each time I try accessing the application on my browser on http://server-address:8080:/user/dashboard, I get a redirection. And then on my console, I get the error:
web_1 | Processing UserController#dashboard (for 103.89.5.96 at 2020-10-25 18:33:15) [GET]
web_1 | Parameters: {"controller"=>"user", "action"=>"dashboard"}
web_1 | [FedenaRescue] No method error undefined method `config_value' for nil:NilClass
web_1 |
web_1 | NoMethodError (undefined method `config_value' for nil:NilClass):
web_1 | app/controllers/application_controller.rb:342:in `set_user_language'
Here's how I fixed it:
Note: This is a temporary fix as I did not have a lot of time to dig into the codebase.
The issue emanates from this code in the app/controllers/application.rb file:
private
def set_user_language
lan = Configuration.find_by_config_key('Locale')
I18n.default_locale = :en
Translator.fallback(true)
I18n.locale = if session[:language].nil?
lan.config_value
else
session[:language]
end
News.new.reload_news_bar
end
I presume that the action set_user_language tries to set up a language for the user based on the default locale language set up on his/her machine/application or the session language, but then the config_value method called on Ian in lan.config_value seems to be Nil.
And this causes the redirect error since it is invoked in the app/controllers/application.rb using a before_filter:
before_filter :set_user_language
So it is called/invoked before any action is completed in the application.
A temporary fix will be to comment out the before_filter for it defined at the top of the app/controllers/application.rb file:
# before_filter :set_user_language
Now you can try accessing the page again.
You can as well consider running the command rake db:seed to seed the data in the db/seed.rb file into the database since it contains some important data that the application will need in order to run smoothly. And it also seems to contain the config_value data for the Configuration.
That's all.
I hope this helps

Error while upgrading to Rails 2.3.11 (HashWithIndifferentAccess error)

Whenever I attempt to create or update an environment that our app uses, I get the following:
NoMethodError (undefined method `base_url' for #<HashWithIndifferentAccess:0x107162f08>):
app/controllers/environments_controller.rb:64:in `check_base_url_for_https'
app/controllers/environments_controller.rb:56:in `update'
haml (3.0.22) lib/sass/plugin/rack.rb:41:in `call'
airbrake (3.0.4) lib/airbrake/rack.rb:27:in `call'
airbrake (3.0.4) lib/airbrake/user_informer.rb:12:in `call'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:162:in `start'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:95:in `start'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:92:in `each'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:92:in `start'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:23:in `start'
/Users/jasonbodak/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/webrick/server.rb:82:in `start'
As I stated in the title, I recently upgraded to Rails 2.3.11. This error never occurred before. Here is the code in my environments_controller.rb that is being executed when the error occurs:
def check_base_url_for_https
#environment = params[:environment]
if /^https:\/\//i =~ #environment.base_url
#ajax_flash = "<ul class='notice'><li>The website you are trying to test is a secure site. If you are using self-signed SSL certificates please see our <a href='http://support.janova.us'>Support Site</a> and search for SSL for important tips on how to access your site.</li></ul>"
end
end
Does anyone know why this code (specifically the line if /^https:\/\//i =~ #environment.base_url no longer works in Rails 2.3.11?
I would like to add that the code in my app/models/environment.rb appears to be sound too:
def base_url
self[:base_url].try(:gsub, /\$/, '')
end
Does anyone see anything wrong with the code above?
I figured it out: params[:environment] was defined as a hash. Thank you, Frost, for forcing me to see this. Therefore, I changed the line #environment = params[:environment] to #environment = Environment.new(params[:environment]) and it worked.

Twitter gem & Rails 3 - TypeError: can't convert Pathname into String

I'm trying to use the twitter gem in a rails 3 app but keep getting the following error:
TypeError: can't convert Pathname into String
Here's the code I'm trying to run:
class Tweet < ActiveRecord::Base
def self.test_tweet
Twitter.user_timeline("sferik").first.text
end
end
Here's the full error message:
TypeError: can't convert Pathname into String
from /home/shane/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:658:in `initialize'
from /home/shane/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:658:in `new'
from /home/shane/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:658:in `connect'
from /home/shane/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:637:in `do_start'
from /home/shane/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:626:in `start'
from /home/shane/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:1168:in `request'
from /home/shane/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:888:in `get'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/faraday-0.7.6/lib/faraday/adapter/net_http.rb:59:in `call'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/faraday-0.7.6/lib/faraday/response.rb:8:in `call'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/faraday-0.7.6/lib/faraday/response.rb:8:in `call'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/faraday-0.7.6/lib/faraday/response.rb:8:in `call'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/faraday-0.7.6/lib/faraday/request/url_encoded.rb:14:in `call'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/faraday-0.7.6/lib/faraday/request/multipart.rb:13:in `call'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/twitter-2.1.1/lib/twitter/request/multipart_with_file.rb:17:in `call'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/twitter-2.1.1/lib/twitter/request/phoenix.rb:13:in `call'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/faraday-0.7.6/lib/faraday/connection.rb:210:in `run_request'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/twitter-2.1.1/lib/twitter/request.rb:23:in `request'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/twitter-2.1.1/lib/twitter/request.rb:11:in `get'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/twitter-2.1.1/lib/twitter/client/timelines.rb:208:in `user_timeline'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/twitter-2.1.1/lib/twitter.rb:17:in `method_missing'
from /home/shane/projects/bv_data/app/models/tweet.rb:5:in `test_tweet'
from (irb):1
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/railties-3.1.2/lib/rails/commands/console.rb:45:in `start'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/railties-3.1.2/lib/rails/commands/console.rb:8:in `start'
from /home/shane/.rvm/gems/ruby-1.9.2-p290#rails312/gems/railties-3.1.2/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I get this error even when running the same code from the console:
Twitter.user_timeline("sferik").first.text
I created a blank test app with the same version of rails and the twitter gem and it runs no problem so I'm not sure what the problem is.
As I had this working before in the app I went back through my commits until I could find a point were it was working and what I did to break it.
So in case anyone happens to be in the same position what I had added was a fix_ssl.rb file in config/initializers which was to address a previous SSL connection issue. Removing this file allowed the Twitter gem to work correctly again.
config/initializers/fix_ssl.rb
require 'open-uri'
require 'net/https'
module Net
class HTTP
alias_method :original_use_ssl=, :use_ssl=
def use_ssl=(flag)
self.ca_file = Rails.root.join('lib/ca-bundle.crt')
self.verify_mode = OpenSSL::SSL::VERIFY_PEER
self.original_use_ssl = flag
end
end
end

using end as column name

I'm maintaining a rails 2.1 application that has some unfortunate choices for column names. For instance, an Event has a start and an end date. Instead of using start_at and end_at the original design uses start and end. Of course this leads to
def end
read_attribute(:end) || 1.hour.from_now
end
I'm surprised this even parses. Is this legal ruby? The real issue is that erb is blowing up with 'stack level too deep' when running a backgroundrb job to send the reminder emails. The template is
<%= [#event.name, #event.when_pretty, #event.location, #event.association,
#event.notes].reject(&:blank?) * "\n" %>
If I deliver_reminder in the console there is no error, but when deliver_reminder is called during the background job, the error occurs.
Question: should I refactor to remove the end method, or is the stack error being caused by something else?
On line #1 of foo/mailer/reminder.rhtml
1: <%= [#event.name, #event.when_pretty, #event.location, #event.association, #event.notes].reject(&:blank?) * "\n" %>
lib/virtual_attributes_and_associations.rb:59:in `virtual_attribute_names'
lib/virtual_attributes_and_associations.rb:83:in `read_attribute_without_virtual'
lib/virtual_attributes_and_associations.rb:86:in `read_attribute'
vendor/rails/activerecord/lib/active_record/base.rb:2720:in `send'
vendor/rails/activerecord/lib/active_record/base.rb:2720:in `clone_attribute_value'
vendor/rails/activerecord/lib/active_record/dirty.rb:127:in `write_attribute'
vendor/rails/activerecord/lib/active_record/attribute_methods.rb:211:in `data='
lib/virtual_attributes_and_associations.rb:9:in `included'
vendor/rails/activesupport/lib/active_support/callbacks.rb:177:in `call'
vendor/rails/activesupport/lib/active_support/callbacks.rb:177:in `evaluate_method'
vendor/rails/activesupport/lib/active_support/callbacks.rb:161:in `call'
vendor/rails/activesupport/lib/active_support/callbacks.rb:93:in `run'
vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `each'
vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `send'
vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `run'
vendor/rails/activesupport/lib/active_support/callbacks.rb:272:in `run_callbacks'
vendor/rails/activerecord/lib/active_record/callbacks.rb:298:in `callback'
vendor/rails/activerecord/lib/active_record/base.rb:1450:in `send'
vendor/rails/activerecord/lib/active_record/base.rb:1450:in `instantiate'
vendor/rails/activerecord/lib/active_record/base.rb:582:in `find_by_sql'
vendor/rails/activerecord/lib/active_record/base.rb:582:in `collect!'
vendor/rails/activerecord/lib/active_record/base.rb:582:in `find_by_sql'
vendor/rails/activerecord/lib/active_record/base.rb:1341:in `find_every'
vendor/rails/activerecord/lib/active_record/base.rb:1376:in `find_one'
vendor/rails/activerecord/lib/active_record/base.rb:1362:in `find_from_ids'
vendor/rails/activerecord/lib/active_record/base.rb:537:in `find'
vendor/rails/activerecord/lib/active_record/associations/belongs_to_association.rb:44:in `find_target'
vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:196:in `load_target'
vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:99:in `reload'
vendor/rails/activerecord/lib/active_record/associations.rb:1084:in `contact'
lib/association.rb:52:in `associated_object'
lib/association.rb:48:in `association'
vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:177:in `send'
vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:177:in `method_missing'
app/views/foo/mailer/reminder.rhtml:1:in `_run_erb_47app47views47foo47mailer47reminder46rhtml'
Turns out the issue was with a library method called association, when I changed that to call associated_object (which was called by Association#association), the stack error no longer occurred.

Rack middleware deadlock

I include this simple Rack Middleware in a Rails application:
class Hello
def initialize(app)
#app = app
end
def call(env)
[200, {"Content-Type" => "text/html"}, "Hello"]
end
end
Plug it in inside environment.rb:
...
Dir.glob("#{RAILS_ROOT}/lib/rack_middleware/*.rb").each do |file|
require file
end
Rails::Initializer.run do |config|
config.middleware.use Hello
...
I'm using Rails 2.3.5, Webrick 1.3.1, ruby 1.8.7
When the application is started in production mode, everything works as expected - every request is intercepted by the Hello middleware, and "Hello" is returned. However, when run in development mode, the very first request works returning "Hello", but the next request hangs.
Interrupting webrick while it is in the hung state yields this:
^C[2010-03-24 14:31:39] INFO going to shutdown ...
deadlock 0xb6efbbc0: sleep:- - /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/reloader.rb:31
deadlock 0xb7d1b1b0: sleep:J(0xb6efbbc0) (main) - /usr/lib/ruby/1.8/webrick/server.rb:113
Exiting
/usr/lib/ruby/1.8/webrick/server.rb:113:in `join': Thread(0xb7d1b1b0): deadlock (fatal)
from /usr/lib/ruby/1.8/webrick/server.rb:113:in `start'
from /usr/lib/ruby/1.8/webrick/server.rb:113:in `each'
from /usr/lib/ruby/1.8/webrick/server.rb:113:in `start'
from /usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
from /usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
from /usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/handler/webrick.rb:14:in `run'
from /usr/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/commands/server.rb:111
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from script/server:3
Something to do with the class reloader in development mode. There is also mention of deadlock in the exception.
Any ideas what might be causing this? Any recommendations as to the best approach to debug this?
UPDATE
$ script/console
Loading development environment (Rails 2.3.5)
>> app.get '/'
=> 200
>> app.get '/'
ThreadError: stopping only thread
note: use sleep to stop forever
from /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/reloader.rb:31:in `lock'
from /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/reloader.rb:31:in `run'
from /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:108:in `call'
from /usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lint.rb:47:in `_call'
from /usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lint.rb:35:in `call'
from /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/integration.rb:316:in `process'
from /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/integration.rb:197:in `get'
from (irb):2
Looks like it might be related to this issue:
https://rails.lighthouseapp.com/projects/8994/tickets/3153-actioncontrollerintegrationsession-broken-in-234
I've come up with a hack that will get me by the time being. It's on the ticket mentioned above.
https://rails.lighthouseapp.com/projects/8994/tickets/3153-actioncontrollerintegrationsession-broken-in-234

Resources