Ruby Net/Http Opening Connection Very Slow

ruby net/http opening connection very slow

It was an issue with DNS server. Switched to google public DNS (8.8.8.8, 8.8.4.4). Thanks @Ineu.

Net::HTTP request connection too slow?

This was solved by a date resynchro. Since all servers' hours are the same, it works like a charm.

How can I handle Connection timed out error in ruby Net/HTTP?

The Timeout::Error is raised by the Net::HTTP.connect method that is executed by start, not by request.

It means that in order to rescue the timeout, the whole Net::HTTP call should be inside the begin block.

  begin   
Net::HTTP.new('example.com', nil, '140.113.182.81', '808').start do |http|
response = http.request
p response
end
rescue Timeout::Error
p 'timed out'
end

Increase connect(2) timeout in RestClient / Net::HTTP on AWS Linux

First of all, you could just increase the tcp_syn_retries configuration updating the /proc/sys/net/ipv4/tcp_syn_retries file. Reference here.

If if doesn't work, I think you will need to activate the SO_KEEPALIVE or TCP_USER_TIMEOUT options. But probably there is no interface for that in rest-client.

So maybe you'll need to make a fork or create the Socket and Socket::Option by yourself.

Mike Perham wrote about it in his blog.

Net::HTTP extremely slow responses for HTTPS requests

The issue was not Ruby or OpenSSL or any of the above libraries. The problem is that IPv6 addresses were not resolving on my MacBook. DNS lookup returned the IPv6 address first, so the libraries tried to connect to that until it timed out and then they connected to the IPv4 addresses which worked just fine.

Disabling IPv6 for OS X Yosemite 10.10.2 worked for me. It's not ideal, but until I can determine another solution, it works.

networksetup -setv6off "Wi-Fi"

Thanks @SteffenUllrich for pointing me in that direction.



Related Topics



Leave a reply



Submit