Execution expired - timeout

Hello guys.

I have one problem with some ruby script I developed. This look a basic
issue to solve, but I did try several things and till now I didn't find
a solution...
This script is basically to do some http requests to trackers. I'm
getting this following exception some time after I start the script:

/usr/lib/ruby/1.8/timeout.rb:60:in `extract_information': execution
expired
from /home/user/NetBeansProjects/trackers/lib/trackers.rb:113:in `run'
from /usr/lib/ruby/1.8/timeout.rb:62:in `timeout'
from /home/user/NetBeansProjects/trackers/lib/trackers.rb:111:in `run'
from /home/user/NetBeansProjects/trackers/lib/trackers.rb:103:in `each'
from /home/user/NetBeansProjects/trackers/lib/trackers.rb:103:in `run'
from /home/user/NetBeansProjects/trackers/lib/trackers.rb:76:in `each'
from /home/user/NetBeansProjects/trackers/lib/trackers.rb:76:in `run'
from /home/user/NetBeansProjects/trackers/lib/main.rb:11

So, the script starts but after a while (the time varies) I get the
above exception.

The structure of the code is like this:

run()
...
infohash.each{ |hash,info|
  ...
  trackers.each{ |t|
    url = ...
    a, b = extract_information(url) #<----------------- Error line(113)
  }
}
end

extract_information(url)
begin
  Timeout::timeout(3) do
    #http call to url
  end
rescue Timeout::Error => e
rescue SystemCallError => e
...
end
end

So, as you can see in extract_information(url) function I handled the
Timeout::Error, so I dont get why is giving the Timeout error. I also
added a timeout in run() function to handle the extract_information(url)
call, like this:

...
begin
  Timeout::timeout(60) do
   a, b = foo(url) #<------------ Error line
  end
rescue Timeout::Error =>e
rescue SystemCallError => e
end

but the result was the same...
Any clues?

Thanks,

Luis

···

--
Posted via http://www.ruby-forum.com/.

Luis G. wrote in post #976533:

Any clues?

1. Write a standalone test program which demonstrates the problem. I
tried the following, but it works fine:

require 'timeout'
require 'open-uri'

begin
Timeout::timeout(1) do
  open("http://1.1.1.1/foo&quot;\).read
end
rescue Timeout::Error
  puts "Rescued"
end

If it works for you too, then keep adjusting it until you find what it
is about your full code which causes the problem.

2. Describe the details of your system. I ran the above under
ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]
(Ubuntu 10.04 x86_64)

3. I see your backtrace doesn't include function 'extract_information',
so I suspect that the error is actually being raised from somewhere
other than where you think.

Regards,

Brian.

···

--
Posted via http://www.ruby-forum.com/\.

maybe it's another error

try capturing it w a generic,

   rescue Exception =>e

best regards -botp

···

On Fri, Jan 21, 2011 at 10:11 PM, Luis G. <l17339@gmail.com> wrote:

rescue Timeout::Error => e
rescue SystemCallError => e
...
end
end

So, as you can see in extract_information(url) function I handled the
Timeout::Error, so I dont get why is giving the Timeout error. I also

Hello guys

Just to tell ya that with

rescue Exception =>e

I can handle the exception, the script keeps running and the error
message I got in 'e' is, of course, the same I said in the first port.

As I told you, this just happens sometimes. So, I'm gonna try to build
an example when I get the exception, put in a file and post it here, so
you can check.

Thanks a lot,

Luis

···

--
Posted via http://www.ruby-forum.com/.

Hey again.

Here is an example to explain you the problem.
In attachment there are 2 files. Put both in the same directory run the
main.rb.

$ruby main.rb

Maybe you need to install some gems... Just check the imports I do in
example.rb
A log file will be created in the same directory. Do a 'tail -f' in the
log file so you can check what is going on.

You should get the execution exception - timeout exception:

E, [2011-01-24T12:13:53.045896 #8446] ERROR -- : execution expired
(#<Class:0xb6dac7ec>)
/usr/lib/ruby/1.8/timeout.rb:60:in `extract_information'
./example.rb:61:in `run'
/usr/lib/ruby/1.8/timeout.rb:62:in `timeout'
./example.rb:60:in `run'
./example.rb:52:in `each'
./example.rb:52:in `run'
./example.rb:37:in `each'
./example.rb:37:in `run'
main.rb:6

for tracker: 'http://tracker4.finalgear.com/announce'

And if you check the code I have the following exception handling in
extract_information(url, log) function:

rescue Timeout::Error => e
(...)
end

So, if it's a timeout exception, why the code don't enter in the
Timeout::Error => e exception handling?

what I'm doing wrong?

Attachments:
http://www.ruby-forum.com/attachment/5783/main.rb
http://www.ruby-forum.com/attachment/5784/example.rb

···

--
Posted via http://www.ruby-forum.com/.

i tested these, and the program is capturing the Timeout error.. note,
i edited some logging info to include file/lineno and retry counts set
to 3. i also moved the rescue timeout block before the rescue
exception...

mine times out because of dns error...

eg,

$ grep ^E log_2011-01-25.txt
E, [2011-01-25T10:35:17.457225 #29426] ERROR -- : [ FILE:
/disk2_2/home/botp/example.rb LINE: 129 ] Fail saving the file
http://tracker.torrentbay.to:6969/announce?info_hash=h��Ҭ�%2F��_��N� "d
(Timeout::Error).
E, [2011-01-25T10:35:22.577837 #29426] ERROR -- : [ FILE:
/disk2_2/home/botp/example.rb LINE: 138 ] Fail saving the file
http://tracker4.finalgear.com/announce?info_hash=h��Ҭ�%2F��_��N� "d
(General Exception).
E, [2011-01-25T10:35:22.579054 #29426] ERROR -- : [ FILE:
/disk2_2/home/botp/example.rb LINE: 138 ] Fail saving the file
http://tracker4.finalgear.com/announce?info_hash=h��Ҭ�%2F��_��N� "d
(General Exception).
E, [2011-01-25T10:35:22.580162 #29426] ERROR -- : [ FILE:
/disk2_2/home/botp/example.rb LINE: 138 ] Fail saving the file
http://tracker4.finalgear.com/announce?info_hash=h��Ҭ�%2F��_��N� "d
(General Exception).
E, [2011-01-25T10:35:22.580250 #29426] ERROR -- : [ FILE:
/disk2_2/home/botp/example.rb LINE: 143 ] Fail saving the file
http://tracker4.finalgear.com/announce?info_hash=h��Ҭ�%2F��_��N� "d
(General Exception)[(3)retries failed].
E, [2011-01-25T10:35:22.580434 #29426] ERROR -- : [ FILE:
/disk2_2/home/botp/example.rb LINE: 144 ] getaddrinfo: Name or
service not known["/usr/local/lib/ruby/1.9.1/net/http.rb:644:in
`initialize'", "/usr/local/lib/ruby/1.9.1/net/http.rb:644:in `open'",
"/usr/local/lib/ruby/1.9.1/net/http.rb:644:in `block in connect'",
"/usr/local/lib/ruby/1.9.1/timeout.rb:44:in `timeout'",
"/usr/local/lib/ruby/1.9.1/timeout.rb:87:in `timeout'",
"/usr/local/lib/ruby/1.9.1/net/http.rb:644:in `connect'",
"/usr/local/lib/ruby/1.9.1/net/http.rb:637:in `do_start'",
"/usr/local/lib/ruby/1.9.1/net/http.rb:632:in `start'",
"/usr/local/lib/ruby/gems/1.9.1/gems/mechanize-1.0.0/lib/mechanize.rb:527:in
`fetch_page'", "/usr/local/lib/ruby/gems/1.9.1/gems/mechanize-1.0.0/lib/mechanize.rb:259:in
`get'", "/disk2_2/home/botp/example.rb:114:in `block in
extract_information'", "/usr/local/lib/ruby/1.9.1/timeout.rb:57:in
`timeout'", "/disk2_2/home/botp/example.rb:112:in
`extract_information'", "/disk2_2/home/botp/example.rb:64:in `block (3
levels) in run'", "/usr/local/lib/ruby/1.9.1/timeout.rb:57:in
`timeout'", "/disk2_2/home/botp/example.rb:63:in `block (2 levels) in
run'", "/disk2_2/home/botp/example.rb:55:in `each'",
"/disk2_2/home/botp/example.rb:55:in `block in run'",
"/disk2_2/home/botp/example.rb:40:in `each'",
"/disk2_2/home/botp/example.rb:40:in `run'", "main.rb:6:in `<main>'"]

best regards -botp

···

On Mon, Jan 24, 2011 at 7:22 PM, Luis G. <l17339@gmail.com> wrote:

Attachments:
http://www.ruby-forum.com/attachment/5783/main.rb
http://www.ruby-forum.com/attachment/5784/example.rb