https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?15910595652016-11-14T17:20:55ZRuby Issue Tracking SystemRuby master - Feature #12928: Use socket conect_timeout in net stdlib for open_timeouthttps://redmine.ruby-lang.org/issues/12928?journal_id=614882016-11-14T17:20:55Zxiewenwei (xie wenwei)xiewenwei@gmail.com
<ul></ul><p>The codes are updated. I use Socket.tcp now. Socket.tcp returns Socket instance. So I need to convert it to TCPSocket instance using TCPSocket.for_fd.</p>
Ruby master - Feature #12928: Use socket conect_timeout in net stdlib for open_timeouthttps://redmine.ruby-lang.org/issues/12928?journal_id=615002016-11-14T20:41:27Znormalperson (Eric Wong)normalperson@yhbt.net
<ul></ul><p><a href="mailto:xiewenwei@gmail.com">xiewenwei@gmail.com</a> wrote:</p>
<blockquote>
<p>net/http, net/pop, net/smtp and net/ftp use <code>Timeout.timeout</code> to calculate connect_timeout.<br>
Timeout.timeout is slow. It creates and destroys a thread every time.<br>
Timeout.timeout is also dangerous. see <a href="http://www.mikeperham.com/2015/05/08/timeout-rubys-most-dangerous-api/" class="external">Timeout: Ruby&#39;s Most Dangerous API</a></p>
</blockquote>
<p>I agree with eliminating Timeout, but I don&#39;t think your<br>
solution is enough because it does not cover timeouts for<br>
DNS resolution (getaddrinfo(3) calls).</p>
<p>For timeouts, we would need to use resolv.rb instead of getaddrinfo(3)<br>
provided by libc to do timeouts without a separate thread. I started<br>
adding timeouts to resolv.rb last year but can&#39;t remember how far I got...<br>
I&#39;m not sure if resolv.rb supports all the features of a modern<br>
getaddrinfo(3), either, AFAIK, not many people use resolv.rb.</p>
<blockquote>
<p>It is more effective and safe to use socket timeout to accomplish that. <br>
Follow is the changes need to do.</p>
<ol>
<li>Replace <code>TCPSocket.open</code> with <code>Socket.tcp</code></li>
<li>Create <code>TCPSocket</code> with <code>TCPSocket.for_fd</code></li>
</ol>
</blockquote>
<p>I don&#39;t think this step should be necessary; Socket and<br>
TCPSocket should be usable interchangeably for stream sockets<br>
(maybe some API calls need to be changed, but I&#39;d rather avoid<br>
the extra object entirely).</p>
Ruby master - Feature #12928: Use socket conect_timeout in net stdlib for open_timeouthttps://redmine.ruby-lang.org/issues/12928?journal_id=615132016-11-15T17:56:23Zxiewenwei (xie wenwei)xiewenwei@gmail.com
<ul><li><strong>Subject</strong> changed from <i>Use socket timeout for net/http and net/pop for open_timeout</i> to <i>Use socket conect_timeout for net stdlib for open_timeout</i></li></ul><p>I changed the codes. Removed TCPSocket.for_fd and used socket directly now.<br>
But I am no idea for DNS resolution timeout. How to fix it?</p>
Ruby master - Feature #12928: Use socket conect_timeout in net stdlib for open_timeouthttps://redmine.ruby-lang.org/issues/12928?journal_id=615142016-11-15T18:04:46Zxiewenwei (xie wenwei)xiewenwei@gmail.com
<ul><li><strong>Subject</strong> changed from <i>Use socket conect_timeout for net stdlib for open_timeout</i> to <i>Use socket conect_timeout in net stdlib for open_timeout</i></li></ul> Ruby master - Feature #12928: Use socket conect_timeout in net stdlib for open_timeouthttps://redmine.ruby-lang.org/issues/12928?journal_id=615272016-11-16T07:07:05Zshugo (Shugo Maeda)
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-1 priority-4 priority-default" href="/issues/12435">Feature #12435</a>: Using connect_nonblock to open TCP connections in Net::HTTP#connect</i> added</li></ul> Ruby master - Feature #12928: Use socket conect_timeout in net stdlib for open_timeouthttps://redmine.ruby-lang.org/issues/12928?journal_id=615492016-11-16T16:54:31Zxiewenwei (xie wenwei)xiewenwei@gmail.com
<ul></ul><p>I got it. It is not simple to fix as I expected before. Thank you.</p>
Ruby master - Feature #12928: Use socket conect_timeout in net stdlib for open_timeouthttps://redmine.ruby-lang.org/issues/12928?journal_id=829092019-12-02T21:20:32Zdylants (Dylan Thacker-Smith)
<ul></ul><p>It looks like we can now use the <code>resolv_timeout</code> <code>Socket.tcp</code> option that was recently added by <a href="https://bugs.ruby-lang.org/projects/ruby-trunk/repository/git/revisions/0e9d56f5e73ed2fd8e7c858fdea7b7d5b905bb64">https://bugs.ruby-lang.org/projects/ruby-trunk/repository/git/revisions/0e9d56f5e73ed2fd8e7c858fdea7b7d5b905bb64</a>.</p>
<p>The only complication with trying to use <code>Socket.tcp</code> 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 <code>Socket.tcp</code> would mean duplicating a lot of the code in that method.</p>
<p>Should we add a combined <code>timeout</code> option to Socket.tcp` so we can easily use that in the net stdlib&#39;s open timeouts?</p>