https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112017-04-06T01:02:24ZRuby Issue Tracking SystemRuby master - Bug #13405: IO#close raises "stream closed"https://redmine.ruby-lang.org/issues/13405?journal_id=640872017-04-06T01:02:24Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul></ul><p>matthewd (Matthew Draper) wrote:</p>
<blockquote>
<p>IO#close is supposed to ignore an IOError indicating the stream is already closed.</p>
</blockquote>
<p>Is it? I can't find a reason behind this (OK, I know the source code is TRYING to behave that way, but not sure if that is ultimately intended or not).</p>
<p>The proposed fix to <code>ruby_error_closed_stream</code> seems a good catch though. I'd like to +1 regardless of the answer to above question.</p> Ruby master - Bug #13405: IO#close raises "stream closed"https://redmine.ruby-lang.org/issues/13405?journal_id=640882017-04-06T02:21:19Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p>"closed stream" and "stream closed" are different.<br>
The former is raised when trying an operation on an IO which has been closed already.<br>
The latter is raised when the IO is closed in an operation by another thread.</p> Ruby master - Bug #13405: IO#close raises "stream closed"https://redmine.ruby-lang.org/issues/13405?journal_id=640922017-04-06T03:24:58Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul></ul><p>nobu (Nobuyoshi Nakada) wrote:</p>
<blockquote>
<p>"closed stream" and "stream closed" are different.</p>
</blockquote>
<p>I then strongly feel that the exception messages are too cryptic. At least "stream closed"'s message shall include that the exception is something thread-related.</p> Ruby master - Bug #13405: IO#close raises "stream closed"https://redmine.ruby-lang.org/issues/13405?journal_id=640942017-04-06T07:30:22Zmatthewd (Matthew Draper)matthew@trebex.net
<ul></ul><p>matthewd (Matthew Draper) wrote:</p>
<blockquote>
<p>IO#close is supposed to ignore an IOError indicating the stream is already closed.</p>
</blockquote>
<p>Sorry, I misread here: <code>io_close</code> ignores the exception, but <code>rb_io_close_m</code> does not. It seems strange that <code>IO.pipe.each(&:close)</code> and <code>IO.pipe {}</code> treat it differently, but that's probably not important right now.</p>
<p>nobu (Nobuyoshi Nakada) wrote:</p>
<blockquote>
<p>"closed stream" and "stream closed" are different.<br>
The former is raised when trying an operation on an IO which has been closed already.<br>
The latter is raised when the IO is closed in an operation by another thread.</p>
</blockquote>
<p>Setting aside the fact the two messages mean the same thing (<code>ruby_error_closed_stream</code> and <code>test_race_closed_stream</code> even both use the "wrong" word order)... is that distinction important? It tells the caller whether the racing thread ran before we started executing this instruction or after we dropped the GVL to do the requested IO, but I don't see how they can use that information: it appears to just expose them to an implementation detail.</p>
<p>Particularly for <code>close</code>: it doesn't attempt any IO operation if it's already closed. So the only way it can raise either exception is if it wasn't closed at the time we entered <code>rb_io_close_m</code>.</p>
<p>Given that, it seems irrelevant to ruby-land exactly which side of the kernel-level close our race landed on. We wanted it closed, and it's closed; raising an exception due to a concurrent close is inconsistent with <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: IO#close should not raise IOError on closed IO objects. (Closed)" href="https://redmine.ruby-lang.org/issues/10718">#10718</a>.</p>
<p>Maybe the top point is relevant after all, and I'm claiming <code>rb_io_close_m</code> <em>should</em> swallow both forms of the exception?</p>
<hr>
<p>I'm not sure, but this sounds like it might actually be related to <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: UNIXServer#closed? returns false after UNIXServer#close called (Closed)" href="https://redmine.ruby-lang.org/issues/13158">#13158</a>, FYI -- the test failures we're seeing are new and relatively frequent: whether that change or another related one, I think they have appeared with the recent batch of releases.</p> Ruby master - Bug #13405: IO#close raises "stream closed"https://redmine.ruby-lang.org/issues/13405?journal_id=641042017-04-07T04:29:29Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-5 priority-4 priority-default closed" href="/issues/10718">Feature #10718</a>: IO#close should not raise IOError on closed IO objects.</i> added</li></ul> Ruby master - Bug #13405: IO#close raises "stream closed"https://redmine.ruby-lang.org/issues/13405?journal_id=641062017-04-07T04:29:48Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul><li><strong>Related to</strong> <i><a class="issue tracker-1 status-5 priority-4 priority-default closed" href="/issues/13158">Bug #13158</a>: UNIXServer#closed? returns false after UNIXServer#close called</i> added</li></ul> Ruby master - Bug #13405: IO#close raises "stream closed"https://redmine.ruby-lang.org/issues/13405?journal_id=641082017-04-07T04:30:15Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul><li><strong>Related to</strong> <i><a class="issue tracker-1 status-5 priority-4 priority-default closed" href="/issues/10153">Bug #10153</a>: File.open block does not throw "No space left on device (Errno::ENOSPC)" if the data fits the buffer of IO.write </i> added</li></ul> Ruby master - Bug #13405: IO#close raises "stream closed"https://redmine.ruby-lang.org/issues/13405?journal_id=641102017-04-07T04:31:12Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Rejected</i> to <i>Open</i></li></ul><p>Let me reopen.</p> Ruby master - Bug #13405: IO#close raises "stream closed"https://redmine.ruby-lang.org/issues/13405?journal_id=641242017-04-09T05:09:50Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset trunk|r58286.</p>
<hr>
<p>thread.c: refine stream closed message</p>
<ul>
<li>thread.c (Init_Thread): [EXPERIMENTAL] refine the "stream<br>
closed" special exception message, by explicating that it is<br>
caused by threading. <a href="/issues/13405">[ruby-core:80583]</a> [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: IO#close raises "stream closed" (Closed)" href="https://redmine.ruby-lang.org/issues/13405">#13405</a>]</li>
</ul>