3

So I have a script that is going to gather some information about some domain names, and in some cases those domain names aren't even registered anymore, and their IP addresses cannot be resolved. When this happens, I can expect the following error message from this:

response = Net::HTTP.start(uri.host, uri.port) {|http|
    http.request(request)
}

error:

[5] pry(WebRequest)* }  
SocketError: Failed to open TCP connection to ekjrhtekjhterhter.net:80 (getaddrinfo: Name or service not known)
from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/net/http.rb:939:in `rescue in block in connect'

I've tried using the open_timeout and read_timeout options, like this:

response = Net::HTTP.start(uri.host, uri.port, :open_timeout => 1, :read_timeout => 1) {|http|
    http.request(request)
}

but it still takes like 5-10 seconds, and then it finally gives me this error:

[9] pry(WebRequest)* }  
Net::OpenTimeout: execution expired
from /home/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/net/http.rb:937:in `initialize'

I basically don't want this request to run any longer than 2 seconds (although I know I have 1 in this example), but for some reason it's still not working.

What am I doing wrong?

LewlSauce
  • 5,326
  • 8
  • 44
  • 91

0 Answers0