我感兴趣的是,要了解在阻止启动的那 60 秒内发生的情况以及导致此问题的常见原因,需要采取哪些步骤。
这是日志文件的样子(没有说明实际发生了什么)
2013-01-14T10:34:17+00:00 app[web.1]: => Booting Thin
2013-01-14T10:34:17+00:00 app[web.1]: => Call with -d to detach
2013-01-14T10:34:17+00:00 app[web.1]: => Rails 3.2.2 application starting in production on http://0.0.0.0:52216
2013-01-14T10:34:17+00:00 app[web.1]: => Ctrl-C to shutdown server
2013-01-14T10:34:23+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2013-01-14T10:34:23+00:00 heroku[web.1]: Stopping process with SIGKILL
2013-01-14T10:34:24+00:00 heroku[web.1]: Process exited with status 137
2013-01-14T10:34:24+00:00 heroku[web.1]: State changed from starting to crashed
我认为如果至少有一个堆栈跟踪显示进程何时被终止,那将非常有帮助。
发生这种情况时您会做什么/检查什么?
PS:我不是在寻找我的案例的答案,而是在寻找一般步骤,每个人都可以从中受益。
最佳答案
我通常首先使用以下代码 (initializers/debug_require.rb) 找出哪些 gem 花费了很长时间:
if ENV['DEBUG_REQUIRE']
require 'benchmark'
def require(file)
@@first ||= Time.now
rc = false
ts = Benchmark.measure do
rc = super
end
if ENV['DEBUG_REQUIRE'].to_f < ts.total
total = ts.format("%t require #{file}")
from_start = (Time.now - @@first).to_i
$stdout.puts "#{total} (#{from_start} second(s) from start)"
end
rc
end
end
将此添加到 config/boot.rb:
require File.expand_path('../initializers/debug_require', __FILE__)
并设置heroku config:add DEBUG_REQUIRE=1
观察日志输出是否需要慢速。
关于ruby-on-rails - 如何在 heroku 上调试 "Error R10 (Boot timeout)"问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14317078/