rack-timeout

Abort requests that are taking too long

  • Owner: zombocom/rack-timeout
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

Rack::Timeout

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

# Gemfile
gem "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.

# Gemfile
gem "rack-timeout", require: "rack/timeout/base"
# config/initializers/rack_timeout.rb

# insert middleware wherever you want in the stack, optionally pass
# initialization arguments, or use environment variables
Rails.application.config.middleware.insert_before Rack::Runtime, Rack::Timeout, service_timeout: 15

Sinatra and other Rack apps

# config.ru
require "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.
use Rack::Timeout, service_timeout: 15

Configuring

Rack::Timeout takes the following settings, shown here with their
default values and associated environment variables.

service_timeout:   15     # RACK_TIMEOUT_SERVICE_TIMEOUT
wait_timeout:      30     # RACK_TIMEOUT_WAIT_TIMEOUT
wait_overtime:     60     # RACK_TIMEOUT_WAIT_OVERTIME
service_past_wait: false  # RACK_TIMEOUT_SERVICE_PAST_WAIT
term_on_timeout:   false  # RACK_TIMEOUT_TERM_ON_TIMEOUT

These settings can be overriden during middleware initialization or
environment variables RACK_TIMEOUT_* mentioned above. Middleware
parameters take precedence:

use Rack::Timeout, service_timeout: 15, wait_timeout: 30

For more on these settings, please see doc/settings.

Further Documentation

Please see the doc folder for further documentation on:

Compatibility

This version of Rack::Timeout is compatible with Ruby 2.1 and up, and,
for Rails apps, Rails 3.x and up.


Copyright © 2010-2016 Caio Chassot, released under the MIT license
http://github.com/heroku/rack-timeout

Main metrics

Overview
Name With Ownerzombocom/rack-timeout
Primary LanguageRuby
Program languageRuby (Language Count: 1)
Platform
License:MIT License
所有者活动
Created At2010-10-29 23:45:16
Pushed At2025-05-27 15:22:26
Last Commit At2022-06-09 11:24:54
Release Count33
Last Release Namev0.7.0 (Posted on )
First Release Namev0.0.4 (Posted on )
用户参与
Stargazers Count897
Watchers Count44
Fork Count160
Commits Count277
Has Issues Enabled
Issues Count115
Issue Open Count5
Pull Requests Count65
Pull Requests Open Count0
Pull Requests Close Count41
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private