From: xiewenwei@... Date: 2016-11-14T17:20:56+00:00 Subject: [ruby-core:78125] [Ruby trunk Feature#12928] Use socket timeout for net/http and net/pop for open_timeout 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: