# Timeouts with Thread#join and Net:HTTP

**URL:** <https://www.ruby-forum.com/t/timeouts-with-thread-join-and-net-http/163201>\
**Category:** Ruby\
**Created:** [March 18, 2009, 8:15am UTC](https://www.ruby-forum.com/t/timeouts-with-thread-join-and-net-http/163201 "2009-03-18T08:15:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rushi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3bc359/32.png) [@Rushi](https://www.ruby-forum.com/u/Rushi)\
**Post date:** [March 18, 2009, 8:15am UTC](https://www.ruby-forum.com/t/timeouts-with-thread-join-and-net-http/163201/1 "2009-03-18T08:15:59Z")

</div>

I have a script doing some multi-threaded work. Every thread is a call  
to an API making a simple post request. My problem is that the script  
throws a Timeout:Error when i’m waiting for all my threads to join  
`
/usr/lib/ruby/1.8/timeout.rb:60:in rbuf_fill': execution expired (Timeout::Error) from test.rb:35:in join’
from test.rb:35
from test.rb:34:in `each’
from test.rb:34
`

Here’s my code - test.rb  
`
amount = 60
@threads = []`

`
1.upto(amount) { |i|
@threads << Thread.new do
puts “New Thread Created #{i}”
```
# This thread makes 10 post requests
1.upto(10) { |j|
  puts "Thread #{i} Try #{j}"
  # => DO post request using Net:HTTP
  Net::HTTP.start("localhost", "80") do |http|
      response = http.request_post("/test/mypost.php?get=value",

```
“a=b,c=d”)
end
}
end
}

Join all the threads we have created
`

`@threads.each{ |thr|
thr.join # Timeout:ERror thrown here after approx 1.5 mins
}
`

Wrapping my thread.join call around Timeout::timeout (http://www.ruby-  
[doc.org/stdlib/libdoc/timeout/rdoc/classes/Timeout.html](http://doc.org/stdlib/libdoc/timeout/rdoc/classes/Timeout.html)) didn’t help  
either.

Any suggestions how to make it _not_ timeout so that I can finish  
making all the API calls? I’ve tried hard but haven’t been able to  
find a solution

---

<div class="post-metadata">

**Author:** ![Rushi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3bc359/32.png) [@Rushi](https://www.ruby-forum.com/u/Rushi)\
**Post date:** [March 19, 2009, 10:35pm UTC](https://www.ruby-forum.com/t/timeouts-with-thread-join-and-net-http/163201/2 "2009-03-19T22:35:50Z")

</div>

On Mar 17, 11:11 pm, Rushi [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> # This thread makes 10 post requests
> 
> either.
> 
> Any suggestions how to make it _not_ timeout so that I can finish  
> making all the API calls? I’ve tried hard but haven’t been able to  
> find a solution

There is a reference to a timeout tool called terminator that you  
might look at in James Edward G. II confreaks presentation  
‘LittleBIGRuby’ It is a quick reference, but it might do what you  
want.

Code is here: [http://rubyforge.org/frs/?group\_id=1024&release\_id=26322](http://rubyforge.org/frs/?group_id=1024&release_id=26322)

I believe Ara Howard wrote it.

Mike B.

---

<div class="post-metadata">

**Author:** ![Rushi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3bc359/32.png) [@Rushi](https://www.ruby-forum.com/u/Rushi)\
**Post date:** [March 20, 2009, 1:18am UTC](https://www.ruby-forum.com/t/timeouts-with-thread-join-and-net-http/163201/3 "2009-03-20T01:18:09Z")

</div>

Rushi wrote:

> # Join all the threads we have created
> 
> @threads.each{ |thr|  
> thr.join # Timeout:ERror thrown here after approx 1.5 mins  
> }
> 
> Wrapping my thread.join call around Timeout::timeout (http://www.ruby-  
> [doc.org/stdlib/libdoc/timeout/rdoc/classes/Timeout.html](http://doc.org/stdlib/libdoc/timeout/rdoc/classes/Timeout.html)) didn’t help  
> either.
> 
> Any suggestions how to make it _not_ timeout so that I can finish  
> making all the API calls? I’ve tried hard but haven’t been able to  
> find a solution

I don’t see how join can timeout at all the way you’ve called it. join  
should never timeout, unless you specify a limit:

## ------------------------------------------------------------ Thread#join thr.join =\> thr thr.join(limit) =\> thr

```
 The calling thread will suspend execution and run _thr_. Does not
 return until _thr_ exits or until _limit_ seconds have passed. If
 the time limit expires, +nil+ will be returned, otherwise _thr_ is
 returned.

```
