https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112021-08-16T12:40:53ZRuby Issue Tracking SystemRuby master - Bug #18077: Marshal.dump(closed_io) raises IOError instead of TypeErrorhttps://bugs.ruby-lang.org/issues/18077?journal_id=932942021-08-16T12:40:53Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>One concern for that [PR], probably may not be a matter, is closed <code>IO</code>s will no longer raise <code>IOError</code> on other <code>Encoding</code> operations too.<br>
[PR]: <a href="https://github.com/ruby/ruby/pull/4746" class="external">https://github.com/ruby/ruby/pull/4746</a></p>
<pre><code>$ ./ruby -v -e 'p Encoding.compatible?(Encoding::US_ASCII, File.open(IO::NULL).tap(&:close))'
ruby 3.1.0dev (2021-08-16T08:00:19Z master a8714b83c4) [x86_64-darwin19]
-e:1:in `internal_encoding': closed stream (IOError)
from -e:1:in `compatible?'
from -e:1:in `<main>'
</code></pre>
<pre><code>$ ./ruby -v -e 'p Encoding.compatible?(Encoding::US_ASCII, File.open(IO::NULL).tap(&:close))'
ruby 3.1.0dev (2021-08-16T12:33:34Z master 9dd58a421b) [x86_64-darwin19]
last_commit=Fix Marshal.dump(closed_io) to raise TypeError
nil
</code></pre> Ruby master - Bug #18077: Marshal.dump(closed_io) raises IOError instead of TypeErrorhttps://bugs.ruby-lang.org/issues/18077?journal_id=933342021-08-18T15:14:31Zlarskanis (Lars Kanis)
<ul></ul><p><a href="https://github.com/ruby/ruby/pull/4749" class="external">https://github.com/ruby/ruby/pull/4749</a> is another fix without the above side effect. Is it OK?</p> Ruby master - Bug #18077: Marshal.dump(closed_io) raises IOError instead of TypeErrorhttps://bugs.ruby-lang.org/issues/18077?journal_id=933352021-08-18T16:51:26ZEregon (Benoit Daloze)
<ul></ul><p>Why does IO#internal_encoding (and external_encoding) raise if the IO is closed?<br>
They could just return the encoding, it's still stored in in the IO instance, and we are not trying to access the <code>fd</code>, right?</p>
<p>JRuby 9.2.17.0 does not raise, and I think it is the better behavior here.</p> Ruby master - Bug #18077: Marshal.dump(closed_io) raises IOError instead of TypeErrorhttps://bugs.ruby-lang.org/issues/18077?journal_id=934032021-08-19T08:20:29Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p>I don't have any strong opinion but @eregon's approach looks a bit better.</p> Ruby master - Bug #18077: Marshal.dump(closed_io) raises IOError instead of TypeErrorhttps://bugs.ruby-lang.org/issues/18077?journal_id=934042021-08-19T08:39:41Zlarskanis (Lars Kanis)
<ul></ul><p><a class="user active user-mention" href="https://bugs.ruby-lang.org/users/772">@Eregon (Benoit Daloze)</a> This was my first though as well, but the current behavior is already defined in ruby-spec.</p>
<p>I would prefer the behavioral change of <code>IO#(in|ex)ternal_encoding</code> being usable on closed IOs and prepared a PR: <a href="https://github.com/ruby/ruby/pull/4758" class="external">https://github.com/ruby/ruby/pull/4758</a></p> Ruby master - Bug #18077: Marshal.dump(closed_io) raises IOError instead of TypeErrorhttps://bugs.ruby-lang.org/issues/18077?journal_id=934492021-08-21T08:03:21Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>Since this is a bug report, I think that the old example in rubyspec should be removed.</p> Ruby master - Bug #18077: Marshal.dump(closed_io) raises IOError instead of TypeErrorhttps://bugs.ruby-lang.org/issues/18077?journal_id=934522021-08-21T10:48:13Zlarskanis (Lars Kanis)
<ul></ul><p>I removed the old example from <a href="https://github.com/ruby/ruby/pull/4758" class="external">https://github.com/ruby/ruby/pull/4758</a> .</p> Ruby master - Bug #18077: Marshal.dump(closed_io) raises IOError instead of TypeErrorhttps://bugs.ruby-lang.org/issues/18077?journal_id=934542021-08-21T21:17:56ZEregon (Benoit Daloze)
<ul></ul><p>larskanis (Lars Kanis) wrote in <a href="#note-5">#note-5</a>:</p>
<blockquote>
<p><a class="user active user-mention" href="https://bugs.ruby-lang.org/users/772">@Eregon (Benoit Daloze)</a> This was my first though as well, but the current behavior is already defined in ruby-spec.</p>
</blockquote>
<p>We can change it in ruby/spec (adding version guards and adding the new expectation).<br>
And in fact I would be glad if the adapted specs would test the more sensible behavior.<br>
ruby/spec often tests whatever the behavior of CRuby is (for best compatibility with other Rubies), it might not always make sense.</p> Ruby master - Bug #18077: Marshal.dump(closed_io) raises IOError instead of TypeErrorhttps://bugs.ruby-lang.org/issues/18077?journal_id=934552021-08-21T21:19:59ZEregon (Benoit Daloze)
<ul></ul><p>I should have read the PR first.<br>
Yes, removing the old example and adding the new one with a version guard is perfect here :)<br>
That allows other implementations & older versions to potentially use the new behavior already, and there is probably very little to no code relying on the previous exception.</p> Ruby master - Bug #18077: Marshal.dump(closed_io) raises IOError instead of TypeErrorhttps://bugs.ruby-lang.org/issues/18077?journal_id=934562021-08-22T01:33:56ZAnonymous
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset <a class="changeset" title="Fix Marshal.dump(closed_io) to raise TypeError and allow encoding on closed IO Mashalling a clos..." href="https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/6594623f623a0982da62cc105094da0701d499da">git|6594623f623a0982da62cc105094da0701d499da</a>.</p>
<hr>
<p>Fix Marshal.dump(closed_io) to raise TypeError and allow encoding on closed IO</p>
<p>Mashalling a closed IO object raised "closed stream (IOError)" before instead of TypeError.<br>
This changes IO#(in|ex)ternal_encoding to still return the encoding even if the underlying FD is closed.</p>
<p>Fixes bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Marshal.dump(closed_io) raises IOError instead of TypeError (Closed)" href="https://bugs.ruby-lang.org/issues/18077">#18077</a></p>