[英]Tomcat is processing requests for a JRuby on Rails app before app is completely loaded
I have an edge case, although a very customer visible one, where Tomcat begins processing requests before all dependencies are properly loaded for a Ruby on Rails stack running underneath JRuby. 我有一个边缘案例,虽然是一个非常客户可见的案例,Tomcat在为JRuby下运行的Ruby on Rails堆栈正确加载所有依赖项之前开始处理请求。
Once Tomcat is restarted, there is something similar to the following happening: 重新启动Tomcat后,会出现类似于以下情况的情况:
undefined method `utc_offset' for nil:NilClass
[RAILS_ROOT]/gems/gems/activesupport-2.3.8/lib/active_support/values/time_zone.rb:206:in `<=>'
This happens when the following code is invoked on one of my services: 在我的某个服务上调用以下代码时会发生这种情况:
@timezones = ActiveSupport::TimeZone.all
If you wait a few more seconds and refresh the requesting page, it'll load no problem. 如果再等几秒钟并刷新请求页面,它将加载没有问题。
Is there a way to ensure that Tomcat does not start processing these requests until the entire stack, ActiveSupport, ActiveRecord etc is loaded? 有没有办法确保Tomcat在加载整个堆栈,ActiveSupport,ActiveRecord等之前不会开始处理这些请求? Has anyone experienced any similar symptoms?
有没有人经历过任何类似症状?
This sounds like a possible bug in JRuby-Rack, assuming that's what you're using to run your Rails app in Tomcat. 这听起来像JRuby-Rack中的一个可能的错误,假设你正在使用它在Tomcat中运行你的Rails应用程序。 JRuby-Rack is supposed to load the entirety of config/environment.rb before it will process requests, so I'm not sure how this would happen to you, but perhaps I've overlooked something.
JRuby-Rack应该在处理请求之前加载整个config / environment.rb,所以我不确定这会发生在你身上,但也许我忽略了一些东西。 Could you share some more data (or maybe code or an app that reproduces the issue) about how you induced the error at http://kenai.com/jira/browse/JRUBY_RACK or http://bugs.jruby.org ?
您可以在http://kenai.com/jira/browse/JRUBY_RACK或http://bugs.jruby.org上分享一些关于如何引发错误的数据(或者可能是代码或应用程序再现问题)吗?
I'm not sure if there is something like that in Tomcat directly, but you can write a javax.servlet.Filter
that will intercept all requests, and deny them until your application is loaded. 我不确定Tomcat中是否存在类似的东西,但您可以编写一个
javax.servlet.Filter
来拦截所有请求,并在加载应用程序之前拒绝它们。 When application is fully loaded, you ask filter to stop denying requests. 当应用程序完全加载时,您要求过滤器停止拒绝请求。 (This isn't pure Ruby solution though).
(虽然这不是纯Ruby解决方案)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.