Net::HTTP extremely slow responses for HTTPS requests
Asked Answered
V

2

6

For some reason, on my development machine I'm getting very, very slow responses for HTTPS requests performed via Net::HTTP. I've tried RestClient and HTTParty and they both have the same issue. It seems to have sprung from nowhere. I've made these requests hundreds of times without issue, but today they are unbearably slow.

pry(main)> puts Time.now; HTTParty.get('https://api.easypost.com/v2/addresses'); puts Time.now;
2015-04-29 08:07:08 -0500
2015-04-29 08:09:39 -0500

As you can see, the response took 2.5 minutes. And it's not just this EasyPost API URL. I've tried numerous SSL requests to servers I know I can connect to (https://google.com, https://weather.com, etc.) and they all result in the same behavior. Also, I noticed that the same thing happens for requests that are redirected from HTTP to HTTPS. Now, check out a non-ssl request:

pry(main)> puts Time.now; HTTParty.get('http://lookitsatravis.com'); puts Time.now;
2015-04-29 08:12:22 -0500
2015-04-29 08:12:22 -0500

Instantaneous. What gives? My guess it is some configuration problem somewhere between Ruby and OpenSSL. I've reinstalled both (using Ruby 2.2.1 and OpenSSL 1.0.2a) and I'm using OS X Yosemite 10.10.2 for what it's worth. Reinstalled all my gems, but the problem persists. I tried changing my DNS settings just in case, but no dice. Is there anywhere else I can look or any configuration I can change that will fix this issue?

Vestavestal answered 29/4, 2015 at 13:27 Comment(3)
Might be a network issue, i.e. some middlebox doing traffic shaping. Check with other software from the same machine to see if it is specific to the machine or really happens only with ruby.Commotion
@SteffenUllrich I just checked cURL/wget/Postman...cURL and Postman work just fine, but wget does not work. It has the exact same behavior. Interestingly, I notice that wget attempts to connect to IPv6 address first which fails. When it connects to the IPv4 address, it completes immediately. So, I believe that the problem is with IPv6 somehow...Vestavestal
Thanks @SteffenUllrich - it was IPv6 causing the issue. Disabling it solved the problem.Vestavestal
V
5

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.

Vestavestal answered 29/4, 2015 at 14:10 Comment(0)
G
-2

What solved the problem for me was disabling the Antivirus

Gandy answered 9/4, 2017 at 8:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.