Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Unable to rescue Errno::ECONNRESET during

Reply
Thread Tools

Unable to rescue Errno::ECONNRESET during

 
 
Yu-shan Fung
Guest
Posts: n/a
 
      11-14-2008
For some reason my rescue clause is not catching this exception. Here's
the stack trace:

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/openssl/buffering.rb:35:in
`sysread': Connection reset by peer (Errno::ECONNRESET)
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/openssl/buffering.rb:35:in
`fill_rbuff'
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/openssl/buffering.rb:106:in
`gets'
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/imap.rb:991:in
`get_response'
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/imap.rb:929:in
`receive_responses'
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/imap.rb:922:in
`initialize'
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/imap.rb:921:in
`start'
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/imap.rb:921:in
`initialize'
from batch/test.rb:6:in `new'
from batch/test.rb:6
from batch/test.rb:4:in `loop'
from batch/test.rb:4

This is the line in test.rb where the error occurs:
imap = Net::IMAP.new('imap.gmail.com', 993, true)


Here's my test code:

loop do
begin
imap = Net::IMAP.new('imap.gmail.com', 993, true)
imap.login('xxxxx', 'yyyyy')
imap.select('Inbox')
imap.expunge
imap.logout
$stdout.putc '.'
$stdout.flush
rescue Net::IMAP::NoResponseError => e
puts "IMAP no response"
rescue Net::IMAP::ByeResponseError => e
# send to log file, db, or email
puts "IMAP bye response"
rescue Errno::ECONNRESET => e
puts "Connection reset by peer"
puts e.backtrace
rescue Exception => e
puts "IMAP Error-#{e.class}\n#{e.message}"
puts e.backtrace
end
sleep 1
end


Either the Errno::RCONNRESET or the the Exception clause should catch
the exception, print the error and continue right? But each time it hits
the ECONNRESET error, it terminates. Any idea why?

Thanks a bunch!
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Brian Candler
Guest
Posts: n/a
 
      11-14-2008
What's interesting is that line 929 of net/imap.rb is in the backtrace:

def receive_responses
while true
begin
resp = get_response # line 929
rescue Exception
@sock.close
@client_thread.raise($!)
break
end

It looks like the exception should be caught here, and explicitly
re-raised in another thread from line 932. You could try adding some
STDERR debugging before and after the get_response line, and inside the
rescue Exception clause.

Maybe "@sock.close" should be "@sock.close rescue nil" in case another
exception is raised then. But line 931 isn't in the backtrace.

Raising and catching the exception in another thread ought to work as
far as I can see:

class Foo
def initialize
t = Thread.current
Thread.start do
t.raise Errno::ECONNRESET
end.join
end
end

begin
f = Foo.new
rescue Errno::ECONNRESET
puts "Caught it: #{$!.backtrace.join("\n")}"
end
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Warning during generating classes through WSIMPORT & Error during xmlvalidation traveller Java 0 01-08-2008 07:00 AM
Mozila rescue from ntuser.dat corruption Adam Smith Firefox 1 10-20-2005 03:31 PM
Datagrid not updated during delete, but updated during insert and update Dmitry Korolyov ASP .Net Datagrid Control 0 09-22-2003 10:57 AM
Unable to read httpcontext during session end Shawn ASP .Net 0 07-15-2003 04:50 PM
rescue the value of a variable type application from a file ".vb" clv ASP .Net 0 07-01-2003 11:23 PM



Advertisments