Errno :: ETIMEDOUT:连接超时 - 在post_form时连接(2)

时间:2014-04-16 17:49:00

标签: ruby-on-rails-3 http-post

我有一个奇怪的问题

我在本地计算机上成功运行如下命令。

uri = URI('http://IP/XXX/XXX.php')
res = Net::HTTP.post_form(uri, 'account' => Settings.account, 'orderno' => order.order_no, 'order_money' => order.total_price, 'order_user' => order.name )

成功消息如下

#<Net::HTTPOK 200 OK readbody=true>

但是,远程部署到生产机器之后。使用相同的代码

我收到如下错误消息

Errno::ETIMEDOUT: Connection timed out - connect(2)
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/net/http.rb:878:in `initialize'
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/net/http.rb:878:in `open'
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/net/http.rb:878:in `block in connect'
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/timeout.rb:52:in `timeout'
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/net/http.rb:877:in `connect'
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/net/http.rb:862:in `do_start'
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/net/http.rb:851:in `start'
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/net/http.rb:582:in `start'
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/net/http.rb:506:in `post_form'

我找到了一些解决方案,例如

  1. 为nethttp请求设置更长的超时
  2. 使用像法拉第,httpclient
  3. 这样的gmes

    但我不知道他们是一些很好的解决方案。

    此外,我想这可能是服务器配置问题。

    因此,我尝试确保生产服务器能够连接到目标服务器。

    sudo traceroute -w 1 -n -T IP
    

    我得到了这些,看起来好吗?

     traceroute to OOO.XXX.YYY (IP), 30 hops max, 60 byte packets
     1  66.212.30.225  0.564 ms  0.599 ms  0.680 ms
     2  96.44.180.41  66.869 ms  66.873 ms  67.103 ms
     3  66.186.197.173  4.233 ms  4.248 ms  4.300 ms
     4  206.223.143.104  0.656 ms  0.730 ms  0.798 ms
     5  60.199.17.57  143.147 ms  143.135 ms  143.133 ms
     6  60.199.18.157  143.067 ms  143.057 ms  143.020 ms
     7  60.199.3.221  143.014 ms  142.997 ms  142.982 ms
     8  60.199.3.142  142.994 ms 60.199.20.221  182.958 ms 60.199.23.14  143.085 ms
     9  60.199.17.118  143.338 ms 60.199.17.114  143.199 ms 60.199.17.118  143.153 ms
    10  219.80.114.86  145.561 ms  145.662 ms  145.608 ms
    11  211.79.200.42  145.508 ms  145.517 ms  145.473 ms
    12  * * *
    13  * * *
    14  * * *
    15  * * *
    16  * * *
    17  * * *
    18  * * *
    19  * * *
    20  * * *
    21  * * *
    22  * * *
    23  * * *
    24  * * *
    25  * * *
    26  * * *
    27  * * *
    28  * * *
    29  * * *
    30  * * *
    

    另外,我发送邮件到目标服务器,确保我遵循发布规则。

    我尽力解决这个问题,但是......它仍然存在~~

1 个答案:

答案 0 :(得分:0)

问题解决了.....

关键是目标服务器阻止来自其他国家/地区的IP。

因此,我问他们为我们设置白名单然后问题解决了。