From: "l0x (Markus Lux)" Date: 2013-03-10T21:10:11+09:00 Subject: [ruby-core:53279] [ruby-trunk - Bug #8067][Open] Checking a network connection in a loop never succeeds even if the connection is available. Issue #8067 has been reported by l0x (Markus Lux). ---------------------------------------- Bug #8067: Checking a network connection in a loop never succeeds even if the connection is available. https://bugs.ruby-lang.org/issues/8067 Author: l0x (Markus Lux) Status: Open Priority: Normal Assignee: Category: Target version: ruby -v: ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux] =begin I want to check for a connection to a specific server with Ruby. So I just wrap the HTTP request into a begin/rescue construct and try again in a few seconds if the connection is not available. ((*Problem*)): If I start the program with no connection available (link down) it will never succeed in finding a connection even if at some time the connection is available (e.g. via ping, browser request). ((*Test case:*)) require 'net/http' loop do begin uri = URI.parse 'http://www.example.com' resp = Net::HTTP.get uri rescue SocketError => se puts se sleep 3 next rescue Exception => e puts e break end puts 'It works!' break end ((*Steps to reproduce:*)) (1) Take network link down (2) Start program (3) -> getaddrinfo: Name or service not known (4) -> ... (5) Turn network link on again (6) Still no connection, same error ((*Expected behavior:*)) Don't throw SocketException as soon as a connection is available. ((*Ruby versions tested:*)) ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-linux] ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux] This may only affect Linux since there exist reports on [1] where people commented that the program works as expected on Windows and Mac. [1] http://stackoverflow.com/questions/15321260/checking-a-network-connection-in-a-loop-never-succeeds-even-if-the-connection-is =end -- http://bugs.ruby-lang.org/