rack-timeout

Abort requests that are taking too long

  • 所有者: zombocom/rack-timeout
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

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

主要指标

概览
名称与所有者zombocom/rack-timeout
主编程语言Ruby
编程语言Ruby (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2010-10-29 23:45:16
推送于2025-05-27 15:22:26
最后一次提交2022-06-09 11:24:54
发布数33
最新版本名称v0.7.0 (发布于 )
第一版名称v0.0.4 (发布于 )
用户参与
星数0.9k
关注者数44
派生数160
提交数277
已启用问题?
问题数115
打开的问题数5
拉请求数65
打开的拉请求数0
关闭的拉请求数41
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?