为什么使用 Rack 和 Phusion Passenger 重新启动 Sinatra 应用程序后第一个请求会出现错误?
在我触摸 tmp/restart.txt 并且我的应用程序重新启动后,第一个请求会抛出错误,通常是关于找不到 Haml::Engine 或其他一些 gem 的错误。 第二个和后续请求都工作正常。 我在运行 Rack 0.4.1 和 Sinatra 0.3.3 的 Dreamhost 上遇到了这个问题,但在转移到我自己的主机并运行更新的 Rack (0.9.1) 和 Sinatra (0.9.0.4) 后,我仍然看到这个问题。
如果您不知道确切的答案,但有关于如何找到答案的提示,请告诉我。
这是我的 config.ru:
require 'rubygems'
require 'sinatra'
disable :run
set :environment, :production
set :raise_errors, true
require 'app.rb'
run Sinatra::Application
After I touch tmp/restart.txt and my app restarts, the first request throws an error, usually something about not finding Haml::Engine or some other gem. The second and subsequent requests all work fine. I was having this problem on Dreamhost which was running Rack 0.4.1 and Sinatra 0.3.3 but after moving to my own host and running a newer Rack (0.9.1) and Sinatra (0.9.0.4) I still see the problem.
If you don't know the exact answer but have tips on how I could track it down, please let me know.
Here's my config.ru:
require 'rubygems'
require 'sinatra'
disable :run
set :environment, :production
set :raise_errors, true
require 'app.rb'
run Sinatra::Application
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会考虑确保您需要所有必要的宝石。 也许您执行此操作的顺序有一些问题导致它第一次失败。 您需要 rubygems 吗?
如果您发布了应用程序的机架配置 (
config.ru
),也可能会有所帮助。I'd look into making sure you're requiring all the necessary gems. Perhaps there's something about the order you're doing it that's causing it to fail the first time. Are you requiring
rubygems
?It might also help if you posted your rack configuration for the app (
config.ru
).该错误是由于 Sinatra gem 加载太晚造成的。 这是解决方案:
The error is caused by the Sinatra gem loading too late. This is the solution: