when trying to connect to an ip address, from within a thread, that
does not exist, using TCPSocket.new(ip, port), it seems that other
threads are blocked until the connection has timed out. This hangs the
entire application for about 20secs.
However i have only noticed this behaviour in windows XP (propably
others too).
Any known workarounds?
I tried to find some information on nonblocking io (sockets) with ruby,
but i gave up,
after googling for around an hour..any links would be appreciated
christoph
<christoph.heindl@gmail.com> schrieb im Newsbeitrag news:1106498039.209351.9940@f14g2000cwb.googlegroups.com...
hi,
when trying to connect to an ip address, from within a thread, that
does not exist, using TCPSocket.new(ip, port), it seems that other
threads are blocked until the connection has timed out. This hangs the
entire application for about 20secs.
However i have only noticed this behaviour in windows XP (propably
others too).
Any known workarounds?
I tried to find some information on nonblocking io (sockets) with ruby,
but i gave up,
after googling for around an hour..any links would be appreciated
christoph
Just a faint hint: I remember having seen something similar some days (or maybe weeks) ago that also involved XP. Can't remember the resolution though. Maybe you just check with ruby-talk.
getaddrinfo: No address associated with nodename (SocketError)
after 1 second.
So this is not a TCPSocket-specific problem, but a DNS resolver problem, probably due to your OS' DNS resolver library performing a blocking call of some kind. There's nothing Ruby can do about this, unless your system provides a non-blocking DNS resolver API.
Changing it to a non-local IP address with no network connection causes:
No route to host - connect(2) (Errno::EHOSTUNREACH)
after 1 second.
Adding a network connection causes it to print . until the network connection times out on:
thanks for your reply.
however, as i pointed out in my initial post, the problem only occurs
on windows. I searched for the problem for quite a while and it seems
that ruby uses Winsock on Windows (instead of Winsock2). Somehow ruby's
scheduler seems not to be able to schedule other threads during a
TCPSocket connection attempt. I think this is not a ruby problem in
general, but has todo with ruby + winsock.
Maybe there are any patches around?
I recently discovered, that my gallery generating script
was generating twice as large pics as in the runs I made
some months ago (in between I made some Debian unstable upgrade
sessions, but the problem may not be Debian specific)
After a while I found out, that if
vga.write("pic.jpg")
is replaced by
vga.write("pic.jpg"){ self.quality = 75 }
then the problem doesn't occur. Therefore the compression
quality seems no longer to be 75% by default ...
thanks for your reply.
however, as i pointed out in my initial post, the problem only occurs
on windows. I searched for the problem for quite a while and it seems
that ruby uses Winsock on Windows (instead of Winsock2). Somehow ruby's
scheduler seems not to be able to schedule other threads during a
TCPSocket connection attempt. I think this is not a ruby problem in
general, but has todo with ruby + winsock.
Maybe there are any patches around?
Hello, works fine with me (windows 2000 + SP4 and all security patches)
....
type foo.rb
require "socket"
Thread.abort_on_exception= true
Thread.new {
sleep 1
begin
TCPSocket.new("xxx.nonexisting.xxx", 1234)
rescue
end
puts "done"
}
I'm just curious, but have you tried to use an ip address instead of
"xxx.nonexisting.xxx". E.g 192.168.0.5 (if 192.168.0.5 is not
reachable).
I have only windows xp systems around, maybe it turns out to be a
windows xp problem?
Thread.new {
sleep 1
begin
TCPSocket.new("192.168.111.222", 1234)
rescue
end
puts "done"
}
loop {
puts "."
sleep 0.25
}
C:\tmp>ruby -v sock.rb
ruby 1.8.2 (2004-11-06) [i386-mswin32]
..
done
..
sock.rb:15:in `sleep': Interrupt from sock.rb:15
from sock.rb:13:in `loop'
from sock.rb:13
No hangs at all, it runs smoothly if I am disconnected from the network, but if I connect my address is in the form 192.168.xxx.yyy ==> re-executing the same script it hangs before writing "done" and then it writes "done" when timeout occurs (20 seconds in my case).
Ciao, Giuliano
···
christoph.heindl@gmail.com wrote:
thanks for your reply Ville.
I'm just curious, but have you tried to use an ip address instead of
"xxx.nonexisting.xxx". E.g 192.168.0.5 (if 192.168.0.5 is not
reachable).
I have only windows xp systems around, maybe it turns out to be a
windows xp problem?
--
If you want to send me an email address should be 'p', then a dot,
followed by 'bossi' at 'quinary', another dot and 'com' at last