中间件如何被删除?

发布于 2024-12-11 07:46:39 字数 261 浏览 1 评论 0原文

rack-timeout 包含在 Gemfile 中,但我们只希望它作为生产中的中间件。因此,在初始化程序中,我们有:

config.middleware.delete Rack::Timeout

检查此行前后显示机架超时已从阵列中删除。不管怎样,请求仍然超时,并且快速“放入”gem 表明它确实是罪魁祸首。

这是因为在调用delete之前中间件堆栈已经构建了吗?或者每次请求时都会读取堆栈?如果是这样的话,可能是什么问题?

rack-timeout is included in the Gemfile, but we only want it as middleware on production. Thus in an initializer, we have:

config.middleware.delete Rack::Timeout

Inspecting before and after this line shows rack-timeout removed from the array. Regardless, requests are still timing out, and a quick 'puts' in the gem shows that it is indeed the culprit.

Is this because the middleware stack has already been built before delete is called? Or is the stack read in every request? If that's the case, what could be the issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

┊风居住的梦幻卍 2024-12-18 07:46:39

为什么不直接像下面这样呢?

group :production do
  gem "rack-timeout"
end

理论上,假设您正在谈论将某些内容放入 config/initializers/ 中,则初始化程序中的中间件删除应该可以在服务器重新启动后解决该问题。


做了更多实验,并将其放入 config/initializers/rack-timeout.rb 中:

if Rails.env.production?
  Rack::Timeout.timeout = 0.5
else
  Rails.configuration.middleware.delete Rack::Timeout
end

这在脚手架控制器中:

sleep 1

在我重新启动开发服务器后,一切看起来都很酷(看不到超时:D) 。所以,也许只是一个坏变量。

我仍然认为使用仅生产组是更好的解决方案。

在 OSX 上使用 Rails 3.2.2 和 ruby​​ 1.9.2-p290 运行。

Why not just have something like the following?

group :production do
  gem "rack-timeout"
end

In theory, the middleware deletion in the initializer should take care of the problem after a server restart, assuming you're talking about putting something in config/initializers/.


Did a little more experimentation and dropped this into config/initializers/rack-timeout.rb:

if Rails.env.production?
  Rack::Timeout.timeout = 0.5
else
  Rails.configuration.middleware.delete Rack::Timeout
end

And this in a scaffolded controller:

sleep 1

Everything seemed cool after I restarted the dev server (no timeouts in sight :D). So, maybe just a bad variable.

I still think using a production-only group is the better solution.

Ran with Rails 3.2.2 with ruby 1.9.2-p290 on OSX.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文