How to remove middleware?

rack-timeout is included in the Gemfile, but we want this to be middleware. Thus, in the initializer we have:

config.middleware.delete Rack::Timeout 

A check before and after this line shows that the timeout in the rack is removed from the array. Despite this, requests still fail, and a quick “put” in the gem shows that this is really the culprit.

Is this because the middleware stack was already created before the delete call? Or is the stack read in every request? If this happens, what could be the problem?

+4
source share
1 answer

Why not just do something like the following?

 group :production do gem "rack-timeout" end 

In theory, uninstalling middleware in the initializer should take care of the problem after the server restarts, assuming you are talking about putting something in config/initializers/ .


I did a little more experimentation and reset this to config/initializers/rack-timeout.rb :

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

And this is in the forest controller:

 sleep 1 

Everything seemed healthy after restarting the dev server (no timeouts in sight: D). So maybe just a bad variable.

I still think that using only the production team is the best solution.

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

+8
source

All Articles