Rails: execution expired on time_zone_select
以下异常间歇性出现:
1 2 3 4 | An ActionView::Template::Error occurred execution expired vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require' |
这是完整的跟踪:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require' vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require' vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency' vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require' vendor/bundle/ruby/1.9.1/gems/tzinfo-0.3.37/lib/tzinfo/timezone.rb:103:in `get' vendor/bundle/ruby/1.9.1/gems/tzinfo-0.3.37/lib/tzinfo/timezone_proxy.rb:80:in `real_timezone' vendor/bundle/ruby/1.9.1/gems/tzinfo-0.3.37/lib/tzinfo/timezone_proxy.rb:52:in `period_for_utc' vendor/bundle/ruby/1.9.1/gems/tzinfo-0.3.37/lib/tzinfo/timezone.rb:458:in `current_period' vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/core_ext/object/try.rb:36:in `try' vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/values/time_zone.rb:212:in `utc_offset' vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/values/time_zone.rb:226:in `<=>' vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/values/time_zone.rb:334:in `sort' vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/values/time_zone.rb:334:in `all' vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_view/helpers/form_options_helper.rb:507:in `time_zone_options_for_select' vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_view/helpers/form_options_helper.rb:612:in `to_time_zone_select_tag' vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_view/helpers/form_options_helper.rb:277:in `time_zone_select' vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_view/helpers/form_options_helper.rb:654:in `time_zone_select' |
当我导航到有问题的页面时,它会很好地加载。对于大多数人来说,它的负载似乎很好,而且只是偶尔发生这样的碰撞。我注意到,每当发生这种情况时,用户代理都是一个bot;最新的是
今天有一个用户登录(幸运的是,那个用户是我……但是无法复制它)。
1 2 | execution expired vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/visitor.rb:15:in `visit' |
特雷斯:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/visitor.rb:15:in `visit' vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/visitor.rb:5:in `accept' vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/emitter.rb:36:in `block in visit_Psych_Nodes_Sequence' vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/emitter.rb:36:in `each' vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/emitter.rb:36:in `visit_Psych_Nodes_Sequence' vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/visitor.rb:15:in `visit' vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/visitor.rb:5:in `accept' vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/emitter.rb:26:in `block in visit_Psych_Nodes_Document' vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/emitter.rb:26:in `each' vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/emitter.rb:26:in `visit_Psych_Nodes_Document' vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/visitor.rb:15:in `visit' vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/visitor.rb:5:in `accept' vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/emitter.rb:20:in `block in visit_Psych_Nodes_Stream' vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/emitter.rb:20:in `each' vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/emitter.rb:20:in `visit_Psych_Nodes_Stream' vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/visitor.rb:15:in `visit' vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/visitor.rb:5:in `accept' vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/nodes/node.rb:46:in `yaml' vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych.rb:243:in `dump' vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/core_ext.rb:14:in `psych_to_yaml' /usr/local/lib/ruby/1.9.1/syck/rubytypes.rb:110:in `to_yaml' vendor/bundle/ruby/1.9.1/gems/dalli-delete-matched-1.1.0/lib/dalli-delete-matched.rb:13:in `write_entry' vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/cache/strategy/local_cache.rb:140:in `write_entry' vendor/bundle/ruby/1.9.1/gems/dalli-2.6.2/lib/active_support/cache/dalli_store.rb:102:in `block in write' vendor/bundle/ruby/1.9.1/gems/dalli-2.6.2/lib/active_support/cache/dalli_store.rb:279:in `block in instrument' vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/notifications.rb:125:in `instrument' vendor/bundle/ruby/1.9.1/gems/dalli-2.6.2/lib/active_support/cache/dalli_store.rb:279:in `instrument' vendor/bundle/ruby/1.9.1/gems/dalli-2.6.2/lib/active_support/cache/dalli_store.rb:101:in `write' vendor/bundle/ruby/1.9.1/gems/dalli-2.6.2/lib/active_support/cache/dalli_store.rb:78:in `fetch' app/models/concerns/roleable.rb:11:in `roles' |
同样,任何见解都会受到欢迎!
我在Heroku上托管它,并按照https://blog.heroku.com/archives/2013/2/27/unicorn_rails上的说明使用独角兽。
回答这个问题:
I'm really really keen to get this fixed, but I really don't have any
idea where to start :/
您可以开始挽救这个错误,记录它,向您发送一封电子邮件,由于它只发生过几次,请重试(使用"retry"命令)。在此之后,您可能需要检查此IP执行的最后一个操作,并查看它是否相关。日志还记录会话变量。
也许你在服务器使用率很高的情况下会超时——试着使用一个工具lime newrelic,甚至是日志内存使用率、CPU使用率和磁盘使用率以及其他信息。
编辑:
因为它不仅是一个操作,所以您可以像下面这样获取ApplicationController上的每个错误:
1 2 3 4 5 6 7 8 9 | class ApplicationController < ActionController::Base rescue_from MyException, :with => :handle_my_exception def handle_my_exception grab_data send_mail retry end end |
我认为这是一个特定的操作,所以我不确定这里的重试是否有效。但即使你不能重试,你仍然可以获得更多的信息并通过电子邮件发送给你自己。当然,您需要添加一个重试计数器逻辑,否则会遇到麻烦。
再次编辑:
考虑得更好,您可以根据请求参数从那里模拟重试,并重定向到。在这个答案中,他解释了如何得到它。别忘了也发送参数。
如何获取RubyonRails中的当前绝对URL?
由于这两个stacktrace完全不同,我敢打赌,页面呈现通常需要很多时间,并且与特定stacktrace中显示的内容无关:actionview将在超时发生时停止在任何地方。
您应该尝试加快渲染过程,例如使用缓存:让僵尸只访问缓存中提供的非动态内容,以减少服务器负载。即使将大的页面拆分为多个部分并缓存这些部分也会有所帮助。
如果仍然遇到这种情况,特别是因为这种情况非常罕见,那么在出现这种异常时,您可以随时自动重新呈现页面。有关一些示例代码,请参阅此日志。
这个问题(无论如何在Heroku上)归结为以下代码:
1 2 3 | ActiveSupport::TimeZone::MAPPING.each do |key,val| TZInfo::Timezone.get(val) end |
所有时区信息都是从一组相当大的文件(每个时区一个)中加载的,然后进行解析。由于某种原因,这项工作非常繁重。也许Ruby的组合在基于文件的IO上不是很有效(?)而HerokuDynos有随机问题击中文件系统。
我目前的解决方法是在所有独角兽工作人员(在_fork之后)中预加载时区信息(基本上运行上述代码)。现在至少问题是确定性的,而不是随机发生的…