title: Errno::ETIMEDOUT: Connection timed out - connect(2) while post_form
body: <p>I have a strange problem</p>
  
  <p>I run commands as below in local machine successfully.</p>
  
  <pre><code>uri = URI('http://IP/XXX/XXX.php')
  res = Net::HTTP.post_form(uri, 'account' =&gt; Settings.account, 'orderno' =&gt; order.order_no, 'order_money' =&gt; order.total_price, 'order_user' =&gt; order.name )
  </code></pre>
  
  <p>success message as below</p>
  
  <pre><code>#&lt;Net::HTTPOK 200 OK readbody=true&gt;
  </code></pre>
  
  <p>However, after deploy to production machine remotely. Using same code</p>
  
  <p>and I got error message as below </p>
  
  <pre><code>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'
  </code></pre>
  
  <p>I found some solutions such as </p>
  
  <ol>
  <li>setting a longer timeout for nethttp request</li>
  <li>use some gmes like faraday, httpclient</li>
  </ol>
  
  <p>But I don't know that they are some good solutions.</p>
  
  <p>Besides, I guess it might be a server configuration issue. </p>
  
  <p>So, I try to make sure production server is able to connect to the destination server.</p>
  
  <pre><code>sudo traceroute -w 1 -n -T IP
  </code></pre>
  
  <p>I got these, it seems well ?</p>
  
  <pre><code> 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  * * *
  </code></pre>
  
  <p>Also, I sent mail to destination server make sure that I follow the post rule.</p>
  
  <p>I try to do my best to fix this bug but....it still there~~</p>