https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112019-03-05T09:30:43ZRuby Issue Tracking SystemRuby master - Bug #15636: ::Socket#to_a hangs Ruby interpreterhttps://bugs.ruby-lang.org/issues/15636?journal_id=769352019-03-05T09:30:43Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p>I don't think it's a bug of socket library.</p>
<p>arturmoczulski (Artur Moczulski) wrote:</p>
<blockquote>
<a name="Result"></a>
<h2 >Result<a href="#Result" class="wiki-anchor">¶</a></h2>
<p>Ruby hangs infinitely.</p>
</blockquote>
<p>No, it desn't. It just takes a long time. It properly exits after 60 seconds (from my machine at least).</p>
<blockquote>
<a name="Expected"></a>
<h2 >Expected<a href="#Expected" class="wiki-anchor">¶</a></h2>
<p>Socket instance converted to an array representation (whatever that might be). I expect this as <code>to_a</code> comes from the <code>::Enumerable</code> mixin included in <code>::IO</code> - one of <code>::Socket</code>'s parent classes.</p>
</blockquote>
<p>Right. This expectation, by far, is accurate.</p>
<p>What is the key point here is that IO's to_a method is ultimately IO#each_line, which reads everything from the IO to split into lines.</p>
<p>In the reproduction code the socket connected to example.com:80, then waits for some response. But in HTTP, you have to send some request before you expect a response. So the remote endpoint waits for your program to send something. After some period of time the remote side gives up. It closes the connection and everything resumes as expected.</p>
<blockquote>
<a name="Background"></a>
<h2 >Background<a href="#Background" class="wiki-anchor">¶</a></h2>
</blockquote>
<p>I am not sure if your problem ultimately sources this behaviour. Because this is a pretty much standardised protocol.</p>