# Force timeout net/http

**URL:** <https://www.ruby-forum.com/t/force-timeout-net-http/143321>\
**Category:** Ruby\
**Created:** [July 17, 2008, 10:27am UTC](https://www.ruby-forum.com/t/force-timeout-net-http/143321 "2008-07-17T10:27:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![al\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@al\_S](https://www.ruby-forum.com/u/al_S)\
**Post date:** [July 17, 2008, 10:27am UTC](https://www.ruby-forum.com/t/force-timeout-net-http/143321/1 "2008-07-17T10:27:37Z")

</div>

Hi List,

I’m using net/http module to connect to a list of hosts.  
How can I force to connect to next host of the list after a timeout?

http.open\_timeout = timeout  
http.read\_timeout = timeout

This doesn’t works! ☹

Thank you list,  
Al

---

<div class="post-metadata">

**Author:** ![al\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@al\_S](https://www.ruby-forum.com/u/al_S)\
**Post date:** [July 18, 2008, 2:38am UTC](https://www.ruby-forum.com/t/force-timeout-net-http/143321/2 "2008-07-18T02:38:25Z")

</div>

Alfonso C. wrote:

> Hi List,
> 
> I’m using net/http module to connect to a list of hosts.  
> How can I force to connect to next host of the list after a timeout?
> 
> http.open\_timeout = timeout  
> http.read\_timeout = timeout
> 
> This doesn’t works! ☹
> 
> Thank you list,  
> Al

If the problem is that it stalls in DNS resolution then  
require ‘resolv-replace’ might help.  
Surrounding your call with  
require ‘timeout’  
begin  
Timeout::timeout(seconds\_to\_timeout) { call here } # might work.  
rescue Timeout::Error  
end  
-R
