Rails: execution expired on time_zone_select

我们两清 提交于 2019-12-05 11:15:42
fotanus

Answering this question:

I'm really really keen to get this fixed, but I really don't have any idea where to start :/

You can start to rescue this error, log it, send one e-mail to you and since it happens only some times, retry (using the "retry" command). After this, you might want to check the last actions that this IP executed and see if it is related. Log also log the session variables.

Maybe you are getting timeouts in high server usage - try to use one tool lime newrelic or even log memory usage, cpu usage and disk usage yourself along with the other info.

EDIT:

Since it is not only one action, you can get every error on ApplicationController like this:

class ApplicationController < ActionController::Base
  rescue_from MyException, :with => :handle_my_exception

  def handle_my_exception
     grab_data
     send_mail
     retry
  end
 end

I thought it was on an specific action, so I'm not sure if retry works here. But even if you can't retry, you can still getting more info and sending by e-mail to yourself this way. Of course you will want to add a retry counter logic, or else you will be in trouble.

EDIT again:

Thinking better, you can simulate a retry from there with a redirect_to based on the request parameters. In this answer he explains how to get it. Don't forget to send the params too.

How do I get the current absolute URL in Ruby on Rails?

As the two stacktraces are completely different, I'll venture that page rendering takes a lot of time generally and is unrelated to what is shown in the specific stacktrace: ActionView will just stop wherever it was when the timeout occurred.

You should try speeding up the rendering process, for example by using the cache: have bots only hit non-dynamic content that's served from cache to reduce server load. Even splitting up large pages into partials and caching those may help a bit.

If you still run into this - especially since it's very infrequent - you could always go for an automatic re-rendering of the page when this exception occurs. See this blog entry for some sample code.

This problem (on Heroku anyway) boils down to the following code:

ActiveSupport::TimeZone::MAPPING.each do |key,val|
  TZInfo::Timezone.get(val)
end

All the time zone information is loaded up from a rather large set of files (one for each time zone) and then parsed. For some reason, this operation is very heavy. Maybe a combination of Ruby not being very efficient at file based IO (?) and the Heroku dynos having random issues hitting the file system.

My current fix is to pre-load the time zone information (basically running the above code) in all Unicorn workers (after_fork). Now at least the problem is deterministic instead of happening randomly...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!