title: Ruby 2.3/Rails - net uri not working anymore after update to Ubuntu 16.04
body: <p>I used to have a working code in my Admin Panel , checking if a url inputed existed and giving a friendly message to the Administrator in case it did not..</p>
  
  <pre><code>def get_url_response(url)
      uri = URI(url)
      request = Net::HTTP.get_response(uri)
      return request
  end
  
  url_response = get_url_response("http://www.example.com").code
      if  url_response === "200" || url_response === "304"
         link_to http://www.example.com, http://www.example.com, target: :blank
      else                                                          
          status_tag("We have a problem ! Response code: "+url_response, :class =&gt; 'red')  
      end
  </code></pre>
  
  <p>It works great when the address ("<a href="http://www.example.com" rel="nofollow noreferrer">http://www.example.com</a>" in the example above) exists, that it to say sends back a 200 code, but as soon as I have a non existing address such as <a href="http://www.examplenotexistingotallyfake.com" rel="nofollow noreferrer">http://www.examplenotexistingotallyfake.com</a>, it should send a 404 code and display ""We have a problem ! Response code:" but it fails with the error message:</p>
  
  <pre><code>SocketError: Failed to open TCP connection to examplenotexistingotallyfake.com:443 (getaddrinfo: Name or service not known)
  from /home/mreisner/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/net/http.rb:882:in `rescue in block in connect'
  </code></pre>
  
  <p>I verified this by opening my Rails console (Rails c) and if I type:</p>
  
  <pre><code> Net::HTTP.get(URI('https://www.examplenotexistingotallyfake.com')).code
  </code></pre>
  
  <p>I get the same error message:</p>
  
  <pre><code> SocketError: Failed to open TCP connection to examplenotexistingotallyfake.com:443 (getaddrinfo: Name or service not known)
  from /home/mreisner/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/net/http.rb:882:in `rescue in block in connect'
  </code></pre>
  
  <p>How can it work for correct urls and not for non-existing addreses? it should just work but send me back a 404 code, shouldn't it?</p>
  
  <p>I can only see the upgrade to Ubutun 16.04 i made a few days ago, that might have tampered with some critical dns/localhost settings as the source of this issue but not 100% totally sure.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>After some suggestions, I now try to avoid the app crashing by rescuing this </p>
  
  <pre><code>def get_url_response(url)       
      begin
          uri = URI(url)
            request = Net::HTTP.get_response(uri)
            return request
  
          rescue SocketError =&gt; e
          puts "Got socket error: #{e}"
          end
  
    end
  </code></pre>
  
  <p>but the app still crashes with a socket Error message</p>