This project is archived and is in readonly mode.

#5 ✓resolved
Cheah Chu Yeow

Introduce ActiveResource::Base.timeout to allow Net::HTTP#read_timeout to be set

Reported by Cheah Chu Yeow | April 17th, 2008 @ 04:48 AM

Active Resource relies on HTTP to access RESTful APIs and as such is inherently susceptible to slow or unresponsive servers. In such cases, your Active Resource method calls could timeout.

This patch allows you to declare a timeout value like so:

class Person < ActiveResource::Base
  self.site = "http://api.people.com:3000/"
  self.timeout = 5
end

This sets the timeout to 5 seconds. It is recommended to set this to a reasonably low value to allow your Active Resource clients (especially if you are using Active Resource in a Rails application) to fail-fast (see http://en.wikipedia.org/wiki/Fai...) rather than cause cascading failures that could incapacitate your server.

Internally, Active Resource relies on Ruby's Net::HTTP library to make HTTP requests. Setting timeout sets the read_timeout of the internal Net::HTTP instance to the same value. The default read_timeout is 60 seconds on most Ruby implementations (which ihmo is too long if your ARes call is in a public-facing controller!).

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Referenced by

Pages