当前位置:  开发笔记 > 后端 > 正文

Drb和"被回收的对象"例外

如何解决《Drb和"被回收的对象"例外》经验,为你挑选了1个好方法。

我正在经历一个奇怪的问题.我的控制器调用drb对象

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

这个Drb对象正在进行一些搜索.

但有时候,在linux环境中,我得到了一个带有这个堆栈跟踪的"0xdba87b30是回收对象"

--- 
- (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

奇怪的是,我无法在我的(windows)开发机器中重现错误,但我只在我的linux测试服务器中得到它(2个mongrels而不是我的机器中的一个).

怎么了?我认为这是一个垃圾收集器问题(重用之前收集的对象),但我不明白我做错了什么.我只需在控制器中创建对象并在其上调用方法.

任何的想法?

谢谢!罗伯托



1> Ripta Pasay..:

该错误意味着您正在尝试提供垃圾收集的对象,这通常是因为该对象超出了服务器上的范围.

你最安全的赌注是弄清楚为什么对象过早被垃圾收集.或者,您可以通过调用禁用服务器的GC GC.disable,这通常是一个坏主意,特别是如果您的服务器长时间运行.

推荐阅读
殉情放开那只小兔子
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有