[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: stream closed (IOError

Yukihiro Matsumoto

10/5/2008 5:36:00 AM

Hi,

In message "Re: stream closed (IOError)"
on Sun, 5 Oct 2008 12:51:52 +0900, "Eric Will" <rakaur@malkier.net> writes:

|This code:
|
| puts "closed?: %s" % @socket.closed?.to_s
|
| begin
| @socket.close
| rescue Exception => e
| return
| rescue IOError => e
| return
| rescue Errno => e
| return
| end
|
|outputs this:
|
|closed?: false
|/Users/rakaur/Sources/wc/ruby/synapse/trunk/lib/xmppd/xmpp/stream.rb:231:in
|`ioloop': stream closed (IOError)
| from /Users/rakaur/Sources/wc/ruby/synapse/trunk/lib/xmppd.rb:196:in `loop'
| from /Users/rakaur/Sources/wc/ruby/synapse/trunk/lib/xmppd.rb:196:in `ioloop'
| from ./bin/xmppd:20
|praxis:trunk rakaur$

It's hard to tell without full executable script, but at least the
exception was raised _outside_ of your code snippet. I believe you
touched @socket after you closed it.

matz.

1 Answer

Eric Will

10/5/2008 2:55:00 PM

0

Line 231 is the @socket.close line. Nothing gets done to the socket
after this, or if it is, it's not getting to it because it crashes on
@socket.close. Nothing should even be touching the entire object after
this, because it sets a flag saying "I'm dead, please GC me."

It's a large program, and the code is available at
http://synapse.malkier.n.... The socket closing is in
lib/xmppd/xmpp/stream.rb. The code right there doesn't have the
exception catching written in, because I removed the thing that causes
this to happen, which is this:

# Check for connection timeouts.
#Timer::Timer.new('check connection timeouts', 60, true) do
# $connections.each do |c|
# c.error('connection-timeout') if ($time - c.rtime) >= 30
# end

I'll try putting the exception around this. One second.

No, that doesn't work. Nor does this:

# Check for connection timeouts.
Timer::Timer.new('check connection timeouts', 60, true) do
$connections.each do |c|
next if c.dead? or c.socket.closed?
c.error('connection-timeout') if ($time - c.rtime) >= 30
end

The socket.closed? returns false, then ONE LINE LATER when I call
socket.close, the IOError is raised and cannot seem to be rescued.

Ok, I've updated the code in svn. Relevant files are
http://synapse.malkier.n.../trunk/lib/xmppd.rb (which is where
the Timer is started),
http://synapse.malkier.n.../trunk/lib/xmppd/timer.rb (which is
the Timers themselves), and
http://synapse.malkier.n.../trunk/lib/xmppd/xmpp/stream.rb
(which is where the socket is closing.

This code outputs this:

/Users/rakaur/Sources/wc/ruby/synapse/trunk/lib/xmppd/xmpp/stream.rb:230:in
`ioloop': stream closed (IOError)
from /Users/rakaur/Sources/wc/ruby/synapse/trunk/lib/xmppd.rb:197:in `loop'
from /Users/rakaur/Sources/wc/ruby/synapse/trunk/lib/xmppd.rb:197:in `ioloop'
from ./bin/xmppd:20

Perhaps it has to do with the timers running in a separate thread?
Putting begin/rescue in the tread doesn't catch it, either.

Thanks.