[ruby-core:78125] [Ruby trunk Feature#12928] Use socket timeout for net/http and net/pop for open_timeout

From: xiewenwei@...
Date: 2016-11-14 17:20:56 UTC
List: ruby-core #78125
Issue #12928 has been updated by xie wenwei.


net/http, net/pop, net/smtp and net/ftp use `Timeout.timeout` to calculate connect_timeout.
Timeout.timeout is slow. It creates and destroys a thread every time.
Timeout.timeout is also dangerous. see [Timeout: Ruby's Most Dangerous API](http://www.mikeperham.com/2015/05/08/timeout-rubys-most-dangerous-api/)

It is more effective and safe to use socket timeout to accomplish that. 
Follow is the changes need to do.
1. Replace `TCPSocket.open` with `Socket.tcp`
2. Create `TCPSocket` with `TCPSocket.for_fd`

[[https://github.com/ruby/ruby/pull/1480]]

----------------------------------------
Feature #12928: Use socket timeout for net/http and net/pop for open_timeout
https://bugs.ruby-lang.org/issues/12928#change-61488

* 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:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next