Net :: HTTP对HTTPS请求的响应非常慢 [英] Net::HTTP extremely slow responses for HTTPS requests

查看:167
本文介绍了Net :: HTTP对HTTPS请求的响应非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,在我的开发机器上,我对通过Net :: HTTP执行的HTTPS请求的响应非常非常缓慢.我已经尝试过RestClient和HTTParty,他们都有相同的问题.它似乎从无处不在.我已经无数次提出这些请求,但是今天它们的速度实在令人难以忍受.

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

如您所见,响应时间为2.5分钟.不仅是这个EasyPost API URL.我已经尝试了对服务器的大量SSL请求,这些服务器我知道我可以连接到( https://google.com https://weather.com 等),它们都将导致相同的行为.另外,我注意到对于从HTTP重定向到HTTPS的请求,也会发生同样的事情.现在,检查一个非SSL请求:

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

瞬时.是什么赋予了?我猜这是Ruby和OpenSSL之间的某个配置问题.我已经重新安装了这两个版本(使用Ruby 2.2.1和OpenSSL 1.0.2a),并且正在使用OS X Yosemite 10.10.2.重新安装了我所有的宝石,但问题仍然存在.我尝试更改DNS设置,以防万一,但没有骰子.我可以找到其他地方或可以更改的任何配置来解决此问题吗?

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?

推荐答案

问题不是Ruby或OpenSSL或上述任何库.问题是我的MacBook无法解析IPv6地址. DNS查找首先返回了IPv6地址,因此库尝试连接到该地址,直到超时为止,然后它们连接到可以正常工作的IPv4地址.

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.

为OS X禁用IPv6优胜美地10.10.2为我工作.这不是理想的方法,但是在我确定其他解决方案之前,它是可行的.

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"

感谢@SteffenUllrich将我指向该方向.

Thanks @SteffenUllrich for pointing me in that direction.

这篇关于Net :: HTTP对HTTPS请求的响应非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆