https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112013-10-21T23:51:34ZRuby Issue Tracking SystemRuby master - Bug #9040: Readline duplicate file descriptors but doesn't close them https://redmine.ruby-lang.org/issues/9040?journal_id=425312013-10-21T23:51:34Zakr (Akira Tanaka)akr@fsij.org
<ul><li><strong>File</strong> <a href="/attachments/4014">readline-release-gvl-3.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/4014/readline-release-gvl-3.patch">readline-release-gvl-3.patch</a> added</li></ul><p>I think it's better to not trust the value of rl_instream and rl_outstream<br>
because they can be modified by other libraries.</p>
<p>I updated my readline patch submitted to [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Readline.readline stops STDOUT? (Closed)" href="https://redmine.ruby-lang.org/issues/8749">#8749</a>].</p> Ruby master - Bug #9040: Readline duplicate file descriptors but doesn't close them https://redmine.ruby-lang.org/issues/9040?journal_id=425342013-10-22T06:59:11Znormalperson (Eric Wong)normalperson@yhbt.net
<ul></ul><p>"akr (Akira Tanaka)" <a href="mailto:akr@fsij.org" class="email">akr@fsij.org</a> wrote:</p>
<blockquote>
<p>Issue <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Readline duplicate file descriptors but doesn't close them (Closed)" href="https://redmine.ruby-lang.org/issues/9040">#9040</a> has been updated by akr (Akira Tanaka).</p>
<p>File readline-release-gvl-3.patch added</p>
</blockquote>
<p>Does poll work reliably with tty FD on non-Linux systems?</p>
<p>Perhaps better to use rb_thread_call_with_gvl and a<br>
rb_wait_for_single_fd wrapper</p> Ruby master - Bug #9040: Readline duplicate file descriptors but doesn't close them https://redmine.ruby-lang.org/issues/9040?journal_id=425432013-10-22T19:47:01Zakr (Akira Tanaka)akr@fsij.org
<ul><li><strong>File</strong> <a href="/attachments/4016">readline-release-gvl-4.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/4016/readline-release-gvl-4.patch">readline-release-gvl-4.patch</a> added</li></ul><p>normalperson (Eric Wong) wrote:</p>
<blockquote>
<p>Does poll work reliably with tty FD on non-Linux systems?</p>
<p>Perhaps better to use rb_thread_call_with_gvl and a<br>
rb_wait_for_single_fd wrapper</p>
</blockquote>
<p>I see. I updated the patch.</p> Ruby master - Bug #9040: Readline duplicate file descriptors but doesn't close them https://redmine.ruby-lang.org/issues/9040?journal_id=425512013-10-23T01:29:15Znormalperson (Eric Wong)normalperson@yhbt.net
<ul></ul><p>"akr (Akira Tanaka)" <a href="mailto:akr@fsij.org" class="email">akr@fsij.org</a> wrote:</p>
<blockquote>
<p>Issue <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Readline duplicate file descriptors but doesn't close them (Closed)" href="https://redmine.ruby-lang.org/issues/9040">#9040</a> has been updated by akr (Akira Tanaka).</p>
<p>File readline-release-gvl-4.patch added</p>
</blockquote>
<p>Fewer ifdefs, so good :> (haven't tested)</p>
<p>Btw, on a separate note, it would be a good idea to check the return<br>
value of fileno() in case another extension accidentally fclose()</p> Ruby master - Bug #9040: Readline duplicate file descriptors but doesn't close them https://redmine.ruby-lang.org/issues/9040?journal_id=425632013-10-23T18:17:39Zakr (Akira Tanaka)akr@fsij.org
<ul><li><strong>File</strong> <a href="/attachments/4018">readline-release-gvl-5.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/4018/readline-release-gvl-5.patch">readline-release-gvl-5.patch</a> added</li></ul><p>normalperson (Eric Wong) wrote:</p>
<blockquote>
<p>Btw, on a separate note, it would be a good idea to check the return<br>
value of fileno() in case another extension accidentally fclose()</p>
</blockquote>
<p>I think avoiding accidental fclose() is not the responsibility of readline_getc().<br>
It is because readline_getc() cannot determine the FILE structure is closed or not.<br>
So the only appropriate action for the situation is rb_bug()<br>
because fileno() for a closed stream is undefined behavior<br>
(possibly SEGV if memory for FILE structure is returned to OS).</p>
<p>I updated the patch.</p> Ruby master - Bug #9040: Readline duplicate file descriptors but doesn't close them https://redmine.ruby-lang.org/issues/9040?journal_id=425832013-10-24T05:23:17Znormalperson (Eric Wong)normalperson@yhbt.net
<ul></ul><p>"akr (Akira Tanaka)" <a href="mailto:akr@fsij.org" class="email">akr@fsij.org</a> wrote:</p>
<blockquote>
<p>Issue <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Readline duplicate file descriptors but doesn't close them (Closed)" href="https://redmine.ruby-lang.org/issues/9040">#9040</a> has been updated by akr (Akira Tanaka).</p>
<p>File readline-release-gvl-5.patch added</p>
<p>normalperson (Eric Wong) wrote:</p>
<blockquote>
<p>Btw, on a separate note, it would be a good idea to check the return<br>
value of fileno() in case another extension accidentally fclose()</p>
</blockquote>
<p>I think avoiding accidental fclose() is not the responsibility of readline_getc().<br>
It is because readline_getc() cannot determine the FILE structure is closed or not.<br>
So the only appropriate action for the situation is rb_bug()<br>
because fileno() for a closed stream is undefined behavior<br>
(possibly SEGV if memory for FILE structure is returned to OS).</p>
</blockquote>
<p>Agreed, thanks.</p>
<p>On a related note: should rb_fd_set/rb_fd_resize call rb_bug on<br>
negative FD? Otherwise it could OOM/SEGV, I think</p> Ruby master - Bug #9040: Readline duplicate file descriptors but doesn't close them https://redmine.ruby-lang.org/issues/9040?journal_id=425852013-10-24T10:23:35Zakr (Akira Tanaka)akr@fsij.org
<ul></ul><p>2013/10/24 Eric Wong <a href="mailto:normalperson@yhbt.net" class="email">normalperson@yhbt.net</a>:</p>
<blockquote>
<p>On a related note: should rb_fd_set/rb_fd_resize call rb_bug on<br>
negative FD? Otherwise it could OOM/SEGV, I think</p>
</blockquote>
<p>It's possible to fail fast.</p>
<h2>I'm not sure wihch is suitable between rb_bug and rb_raise, though.<br>
Negative FD can be determined safely.</h2>
<p>Tanaka Akira</p> Ruby master - Bug #9040: Readline duplicate file descriptors but doesn't close them https://redmine.ruby-lang.org/issues/9040?journal_id=426342013-10-27T21:04:17Zakr (Akira Tanaka)akr@fsij.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>This issue was solved with changeset r43439.<br>
Eamonn, thank you for reporting this issue.<br>
Your contribution to Ruby is greatly appreciated.<br>
May Ruby be with you.</p>
<hr>
<ul>
<li>
<p>ext/readline/readline.c: Include ruby/thread.h for<br>
rb_thread_call_without_gvl2.<br>
(readline_rl_instream, readline_rl_outstream): Record FILE<br>
structures allocated by this extension.<br>
(getc_body): New function extracted from readline_getc.<br>
(getc_func): New function.<br>
(readline_getc): Use rb_thread_call_without_gvl2 to invoke getc_func.<br>
<a href="/issues/7100">[ruby-dev:47033]</a> [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Readline.readline stops STDOUT? (Closed)" href="https://redmine.ruby-lang.org/issues/8749">#8749</a>]<br>
(clear_rl_instream, clear_rl_outstream): Close FILE structure<br>
allocated by this extention reliably. <a href="/issues/9040">[ruby-core:57951]</a> [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Readline duplicate file descriptors but doesn't close them (Closed)" href="https://redmine.ruby-lang.org/issues/9040">#9040</a>]<br>
(readline_readline): Use clear_rl_instream and clear_rl_outstream.<br>
(readline_s_set_input): Set readline_rl_instream.<br>
(readline_s_set_output): Set readline_rl_outstream.<br>
(Init_readline): Don't call readline_s_set_input because<br>
readline_getc doesn't block other threads for any FILE structure now.</p>
<p><a href="/issues/7100">[ruby-dev:47033]</a> [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Readline.readline stops STDOUT? (Closed)" href="https://redmine.ruby-lang.org/issues/8749">#8749</a>] reported by Nobuhiro IMAI.<br>
<a href="/issues/9040">[ruby-core:57951]</a> [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Readline duplicate file descriptors but doesn't close them (Closed)" href="https://redmine.ruby-lang.org/issues/9040">#9040</a>] reporeted by Eamonn Webster.</p>
</li>
</ul> Ruby master - Bug #9040: Readline duplicate file descriptors but doesn't close them https://redmine.ruby-lang.org/issues/9040?journal_id=617482016-11-26T08:05:55Zwanabe (_ wanabe)s.wanabe@gmail.com
<ul><li><strong>Related to</strong> <i><a class="issue tracker-1 status-8 priority-4 priority-default closed" href="/issues/12950">Bug #12950</a>: irb: 'input-method.rb:151: [BUG] Segmentation fault' / 'malloc(): smallbin double linked list corrupted'</i> added</li></ul>