Skip to content
Abort requests that are taking too long
Find file
Pull request Compare This branch is 18 commits ahead, 166 commits behind heroku:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib
MIT-LICENSE
README.markdown
rack-timeout.gemspec

README.markdown

note: This branch is not yet ready for use. It has a memory leak that needs to be investigated when I have time. --@jjb

Rack::Timeout

<<-CUTE
▄██████████████▄▐█▄▄▄▄█▌
██████▌▄▌▄▐▐▌███▌▀▀██▀▀
████▄█▌▄▌▄▐▐▌▀███▄▄█▌
▄▄▄▄▄██████████████▀

Our systems are over
capacity and could not
complete your requeset.

Your browser will
automatically try again
in 10 seconds.
CUTE

Usage

Installation

You will almost certainly want to make Rack::Timeout the very first middleware. (The only thing that you might possibly want to put before it is an exception/error reporter).

# config.ru
require 'rack/timeout'
use Rack::Timeout
# ... configuration (see below for options) ...
# ... other middleware ...
run MyApp::Application # if it's a Rails app

Rails 3 app

# Gemfile
gem "rack-timeout", github: 'ganxy/rack-timeout'

# config/initializers/timeout.rb
Rack::Timeout.time = 10
#... other config

Configuration

Changing the timeout time (default is 15)

Rack::Timeout.time = 25

Setting a custom handler to report timeouts

Rack::Timeout.reporter = lambda{ |exception, env|
  ::Exceptional::Catcher.handle_with_rack(exception, env, Rack::Request.new(env))
}

Specifying a custom error page and title

Rack::Timeout.error_page = 'http://cdn.example.com/503.html'
Rack::Timeout.error_title = "We're sorry :'-("

Here be dragons

Ruby Timeout relies on threads. If your app or any of the libraries it depends on is not thread-safe, you may run into issues using rack-timeout.

TODO

  • figure out why when iserted before rack lock and using Rack::Deflater results in "Unexpected error while processing request: Attempt to unlock a mutex which is not locked", starting from when I started using the wrapper-thread.
  • tidier configuration system
  • Figure out who made the text failwhale and give attribution.

Copyright © 2012 John Bachir
Copyright © 2010 Caio Chassot
released under the MIT license

Something went wrong with that request. Please try again.