Drb和“被回收的对象” 例外
我遇到了一个奇怪的问题。 我的控制器调用 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 测试服务器中得到它(我的机器里有两个杂种,而不是一个)。
怎么了? 我认为这是一个垃圾收集器问题(在重用之前收集对象),但我不明白我在哪里做错了。 我只是在控制器中创建对象并调用它的方法。
任何想法?
谢谢! 罗伯托
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该错误意味着您正在尝试提供已被垃圾收集的对象,这通常是因为该对象超出了服务器的范围。
最安全的选择是首先弄清楚为什么该对象会被过早地垃圾收集。 或者,您可以通过调用 GC.disable 来禁用服务器的 GC,这通常是一个坏主意,尤其是在您的服务器长时间运行的情况下。
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.有一种方法可以延迟服务器上传递给客户端的对象的垃圾回收:
请参阅https://ruby-doc.org/stdlib-2.5.3/libdoc/drb/rdoc/DRb/TimerIdConv.html
There is a way to delay garbage collection for the object passed to the client on the server:
See https://ruby-doc.org/stdlib-2.5.3/libdoc/drb/rdoc/DRb/TimerIdConv.html
您是否有可能在服务器中多次调用 DRb.start_service ?
Is it possible you are calling DRb.start_service more than once in the server?