# ActiveResource timeout not functioning?

**URL:** <https://www.ruby-forum.com/t/activeresource-timeout-not-functioning/172173>\
**Category:** Rails\
**Created:** [July 16, 2009, 8:10am UTC](https://www.ruby-forum.com/t/activeresource-timeout-not-functioning/172173 "2009-07-16T08:10:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bencahen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecb155/32.png) [@bencahen](https://www.ruby-forum.com/u/bencahen)\
**Post date:** [July 16, 2009, 8:10am UTC](https://www.ruby-forum.com/t/activeresource-timeout-not-functioning/172173/1 "2009-07-16T08:10:01Z")

</div>

I’m trying to contact a REST API using ActiveResource on Rails 2.3.2.

I’m attempting to use the timeout functionality so that if the resource  
I’m contacting is down I can fail quickly - I’m doing this with the  
following:

class WorkspaceResource \< ActiveResource::Base  
self.timeout = 5  
self.site = “[http://mysite.com/restAPI](http://mysite.com/restAPI)”  
end

However, when I try to contact the service when I know it isn’t  
available, the class only times out after the default 60 seconds. I can  
see from the error stack that the timeout error does indeed come from an  
ActiveResource class in my gem folder that has the proper functions to  
allow timeout settings, but my set timeout never seems to work.

Any thoughts?

---

<div class="post-metadata">

**Author:** ![bencahen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecb155/32.png) [@bencahen](https://www.ruby-forum.com/u/bencahen)\
**Post date:** [July 16, 2009, 8:23pm UTC](https://www.ruby-forum.com/t/activeresource-timeout-not-functioning/172173/2 "2009-07-16T20:23:39Z")

</div>

So apparently the issue is not that timeout is not functioning. I can  
run a server locally, make it not return a response within the timeout  
limit, and see that timeout works.

The issue is in fact that if the server does not accept the connection,  
timeout does not function as I expected it to - it doesn’t function at  
all. It appears as though timeout only works when the server accepts the  
connection but takes too long to respond.

To me, this seems like an issue - shouldn’t timeout also work when the  
server I’m contacting is down? If not, there should be another mechanism  
to stop a bunch of requests from hanging…anyone know of a quick way to  
do this?

Ben Porterfield wrote:

> I’m trying to contact a REST API using ActiveResource on Rails 2.3.2.
> 
> I’m attempting to use the timeout functionality so that if the resource  
> I’m contacting is down I can fail quickly - I’m doing this with the  
> following:
> 
> class WorkspaceResource \< ActiveResource::Base  
> self.timeout = 5  
> self.site = “[http://mysite.com/restAPI](http://mysite.com/restAPI)”  
> end
> 
> However, when I try to contact the service when I know it isn’t  
> available, the class only times out after the default 60 seconds. I can  
> see from the error stack that the timeout error does indeed come from an  
> ActiveResource class in my gem folder that has the proper functions to  
> allow timeout settings, but my set timeout never seems to work.
> 
> Any thoughts?
