Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
99 lines (68 sloc) 2 KB


This rack middleware intends to handle retry logic for rack-client.

Rack::Idempotent rescues and retries low-level errors and 'safe to retry' http response codes.

Default retry limit is currently set to 5.

Handled low-level Net::HTTP exceptions include:

  • Errno::ETIMEDOUT

Response status codes that are retried:

  • 408: Request Timeout
  • 502: Bad Gateway
  • 503: Service Unavailable
  • 504: Gateway Timeout

If the retry limit is exceeded, Rack::Idemptotent will raise Rack::Idempotent::RetryLimitExceeded.

The exceptions raised are stored as an array available via Rack::Idempotent::RetryLimitExceeded#idempotent_exceptions


Add this line to your application's Gemfile:

gem 'rack-idempotent'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rack-idempotent


Add Rack::Idempotent as a Rack::Client middleware as close to the handler as possible:

client = do
  use EY::ApiHMAC::ApiAuth::Client, *ServiceClient.hmac_keys
  use Rack::Idempotent
  run Rack::Client::Handler::NetHTTP


Exponential Backoff

  • Defaults
    • max_retries = 5
    • min_retry_interval = 0.5 (seconds)
    • max_retry_interval = 1800 (seconds) do
  use Rack::Idempotent, {
    :retry =>
      :max_retries        => 50,
      :min_retry_interval => 1.0,
      :max_retry_interval => 30,
  use Rack::Lint
  run App

Immediate Retry do
  use Rack::Idempotent, {
    :retry => 50),
  use Rack::Lint
  run App

Running Tests

$ bundle exec rake


  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
Jump to Line
Something went wrong with that request. Please try again.