Increase connect(2) timeout in RestClient / Net::HTTP on AWS Linux
<p>I'm using <a href="https://github.com/rest-client/rest-client" rel="nofollow noreferrer">rest-client</a> to POST to a very slow web service. I'm setting <code>timeout</code> to 600 seconds, and I've confirmed that it's being passed down to Net::HTTP's <code>@read_timeout</code> and <code>@open_timeout</code>.</p>

<p>However, after about two minutes, I get a low-level timeout error, <code>Errno::ETIMEDOUT: Connection timed out - connect(2)</code>:</p>

<p>The relevant part of the backtrace is</p>

<pre><code>Operation timed out - connect(2) for [myhost] port [myport]
/Users/dmoles/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/net/http.rb:879:in `initialize'
/Users/dmoles/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/net/http.rb:879:in `open'
/Users/dmoles/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/net/http.rb:879:in `block in connect'
/Users/dmoles/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/timeout.rb:88:in `block in timeout'
/Users/dmoles/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/timeout.rb:98:in `call'
/Users/dmoles/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/timeout.rb:98:in `timeout'
/Users/dmoles/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/net/http.rb:878:in `connect'
/Users/dmoles/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/net/http.rb:863:in `do_start'
/Users/dmoles/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/net/http.rb:852:in `start'
/Users/dmoles/.rvm/gems/ruby-2.2.5/gems/rest-client-2.0.0/lib/restclient/request.rb:766:in `transmit'
/Users/dmoles/.rvm/gems/ruby-2.2.5/gems/rest-client-2.0.0/lib/restclient/request.rb:215:in `execute'
/Users/dmoles/.rvm/gems/ruby-2.2.5/gems/rest-client-2.0.0/lib/restclient/request.rb:52:in `execute'
</code></pre>

<p>It looks like the line of code throwing the error is</p>

<pre><code>TCPSocket.open(conn_address, conn_port, @local_host, @local_port)
</code></pre>

<p>It seems as though the underlying <code>connect(2)</code> system call has a timeout of about two minutes, and the timeout parameters passed to Net::HTTP can only shorten that, not lengthen it. Is there a way to modify the socket parameters to set a longer timeout?</p>

<p><strong>Edited to add:</strong> This only appears to be a problem on our AWS Linux servers -- on my MacOS development machine, the ten-minute timeout works. I assume the default <code>connect()</code> timeout is longer on MacOS/BSD, but I don't really know.</p>