You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Abort requests that are taking too long; an exception is raised.
A timeout of 15s is the default. It's recommended to set the timeout as
low as realistically viable for your application. You can modify this by
setting the RACK_TIMEOUT_SERVICE_TIMEOUT environment variable.
There's a handful of other settings, read on for details.
Rack::Timeout is not a solution to the problem of long-running requests,
it's a debug and remediation tool. App developers should track
rack-timeout's data and address recurring instances of particular
timeouts, for example by refactoring code so it runs faster or
offsetting lengthy work to happen asynchronously.
Upgrading
For fixing issues when upgrading, please see UPGRADING.
Basic Usage
The following covers currently supported versions of Rails, Rack, Ruby,
and Bundler. See the Compatibility section at the end for legacy
versions.
Rails apps
# Gemfilegem"rack-timeout"
This will load rack-timeout and set it up as a Rails middleware using
the default timeout of 15s. The middleware is not inserted for the test
environment. You can modify the timeout by setting a
RACK_TIMEOUT_SERVICE_TIMEOUT environment variable.
Rails apps, manually
You'll need to do this if you removed Rack::Runtime from the
middleware stack, or if you want to determine yourself where in the
stack Rack::Timeout gets inserted.
# config/initializers/rack_timeout.rb# insert middleware wherever you want in the stack, optionally pass# initialization arguments, or use environment variablesRails.application.config.middleware.insert_beforeRack::Runtime,Rack::Timeout,service_timeout: 15
Sinatra and other Rack apps
# config.rurequire"rack-timeout"# Call as early as possible so rack-timeout runs before all other middleware.# Setting service_timeout or `RACK_TIMEOUT_SERVICE_TIMEOUT` environment# variable is recommended. If omitted, defaults to 15 seconds.useRack::Timeout,service_timeout: 15
Configuring
Rack::Timeout takes the following settings, shown here with their
default values and associated environment variables.
These settings can be overridden during middleware initialization or
environment variables RACK_TIMEOUT_* mentioned above. Middleware
parameters take precedence: