Issue #12928 has been updated by dylants (Dylan Thacker-Smith).


It looks like we can now use the `resolv_timeout` `Socket.tcp` option that was recently added by https://bugs.ruby-lang.org/projects/ruby-trunk/repository/git/revisions/0e9d56f5e73ed2fd8e7c858fdea7b7d5b905bb64.

The only complication with trying to use `Socket.tcp` now would be that it has two separate timeouts that are specified at the same time, but the net stdlib uses a combine open timeout that include DNS resolving and TCP connecting.  Preserving that behaviour would mean using the open timeout for DNS resolution, then using the remaining time for the connect timeout.  Doing this outside `Socket.tcp` would mean duplicating a lot of the code in that method.

Should we add a combined `timeout` option to Socket.tcp` so we can easily use that in the net stdlib's open timeouts?

----------------------------------------
Feature #12928: Use socket conect_timeout in net stdlib for open_timeout
https://bugs.ruby-lang.org/issues/12928#change-82909

* Author: xiewenwei (xie wenwei)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------

Current net/http and net/pop use Timeout.timeout to tigger open_timeout event.
Timeout.timeout is slow. It will create and destroy a thread every time.
Timeout.timeout is also dangerous. see [[http://www.mikeperham.com/2015/05/08/timeout-rubys-most-dangerous-api/]]

It is more effective and safe to use socket timeout to accomplish this. 
Follow is the changes need to do.
1. Replace TCPSocket.open with Socket.new
2. Use socket.connect_nonblock and IO.select to connect and trigger timeout event.

The pull request is here:
[[https://github.com/ruby/ruby/pull/1480]]






-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>