Search code examples
ruby-on-railsrubydrb

Drb and "is recycled object" exception


I'm running in a strange issue. My controller calls a drb object

@request_handler = DRbObject.new(nil, url)
availability_result = @request_handler.fetch_availability(request, @reservation_search, params[:selected_room_rates])

and this Drb object is making some searches.

but sometimes, in a linux environments, I get a "0xdba87b30 is recycled object" with this stacktrace

--- 
- (druby://10.254.143.159:9001) /usr/lib/ruby/1.8/drb/drb.rb:375:in `_id2ref'
- (druby://10.254.143.159:9001) /usr/lib/ruby/1.8/drb/drb.rb:375:in `to_obj'
- (druby://10.254.143.159:9001) /usr/lib/ruby/1.8/drb/drb.rb:1402:in `to_obj'
- (druby://10.254.143.159:9001) /usr/lib/ruby/1.8/drb/drb.rb:1704:in `to_obj'
- (druby://10.254.143.159:9001) /usr/lib/ruby/1.8/drb/drb.rb:613:in `recv_request'
- (druby://10.254.143.159:9001) /usr/lib/ruby/1.8/drb/drb.rb:911:in `recv_request'
- (druby://10.254.143.159:9001) /usr/lib/ruby/1.8/drb/drb.rb:1530:in `init_with_client'
- (druby://10.254.143.159:9001) /usr/lib/ruby/1.8/drb/drb.rb:1542:in `setup_message'
- (druby://10.254.143.159:9001) /usr/lib/ruby/1.8/drb/drb.rb:1494:in `perform'
- (druby://10.254.143.159:9001) /usr/lib/ruby/1.8/drb/drb.rb:1589:in `main_loop'
- (druby://10.254.143.159:9001) /usr/lib/ruby/1.8/drb/drb.rb:1585:in `loop'
- (druby://10.254.143.159:9001) /usr/lib/ruby/1.8/drb/drb.rb:1585:in `main_loop'
- (druby://10.254.143.159:9001) /usr/lib/ruby/1.8/drb/drb.rb:1581:in `start'
- (druby://10.254.143.159:9001) /usr/lib/ruby/1.8/drb/drb.rb:1581:in `main_loop'
- (druby://10.254.143.159:9001) /usr/lib/ruby/1.8/drb/drb.rb:1430:in `run'
- (druby://10.254.143.159:9001) /usr/lib/ruby/1.8/drb/drb.rb:1427:in `start'
- (druby://10.254.143.159:9001) /usr/lib/ruby/1.8/drb/drb.rb:1427:in `run'
- (druby://10.254.143.159:9001) /usr/lib/ruby/1.8/drb/drb.rb:1347:in `initialize'
- (druby://10.254.143.159:9001) /usr/lib/ruby/1.8/drb/drb.rb:1627:in `new'
- (druby://10.254.143.159:9001) /usr/lib/ruby/1.8/drb/drb.rb:1627:in `start_service'
- (druby://10.254.143.159:9001) ./core/request_handler.rb:244
- (druby://10.254.143.159:9001) /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
- (druby://10.254.143.159:9001) /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
- (druby://10.254.143.159:9001) /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:510:in `require'
- (druby://10.254.143.159:9001) /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:355:in `new_constants_in'
- (druby://10.254.143.159:9001) /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:510:in `require'
- (druby://10.254.143.159:9001) core/request_handler.rb:31
- (druby://10.254.143.159:9001) core/request_handler.rb:29:in `each'
- (druby://10.254.143.159:9001) core/request_handler.rb:29
- app/drops/room_drop.rb:18:in `room_rates'
- lib/liquid/liquid_templates.rb:47:in `parse_template'
- lib/liquid/liquid_templates.rb:21:in `render_liquid_template_without_layout'
- app/helpers/skins_helper.rb:6:in `render_respond_by_format'
- app/helpers/skins_helper.rb:4:in `render_respond_by_format'
- app/helpers/skins_helper.rb:25:in `render_availability_action'
- app/controllers/web_reservations_controller.rb:109:in `availability_simplified'
- /usr/bin/mongrel_rails:19:in `load'
- /usr/bin/mongrel_rails:19

The strange thing is that I can't reproduce the error in my (windows) development machine, but I get it only in my linux testing server (2 mongrels instead of one in my machine).

What's wrong? I think it is a garbage collector problem (object collected before reusing it), but I don't understand where I'm doing something wrong. I simply create the object in my controller and call a method on it.

Any idea?

Thanks! Roberto


Solution

  • The error means that you're trying to serve an object that's been garbage collected, which usually happens because the object went out of scope on the server.

    Your safest bet is figuring out why the object was prematurely garbage-collected in the first place. Alternatively, you could disable the server's GC by calling GC.disable, which is usually a bad idea, especially if your server is long-running.