Issue #12928 has been updated by xie wenwei.

Subject changed from Use socket timeout for net/http and net/pop for open_timeout to Use socket conect_timeout for net stdlib for open_timeout


I changed the codes. Remove TCPSocket.for_fd and use socket directly now.
But I am no idea for DNS resolution timeout. How to fix it?

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

* Author: xie wenwei
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------

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>