https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112017-05-01T13:22:32ZRuby Issue Tracking SystemRuby master - Bug #13526: Segmentation fault at 0x0055c2e58e8920 ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]https://bugs.ruby-lang.org/issues/13526?journal_id=646252017-05-01T13:22:32Zwanabe (_ wanabe)s.wanabe@gmail.com
<ul></ul><p>vlad-leonov (Vladislav Leonov) wrote:</p>
<blockquote>
<p>-- Ruby level backtrace information ----------------------------------------<br>
/home/vlad/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.8.2/lib/puma/thread_pool.rb:120:in block in spawn_thread'</p>
</blockquote>
<p>Ruby level backtrace shows there are some threads.</p>
<blockquote>
<p>-- C level backtrace information -------------------------------------------<br>
/home/vlad/.rbenv/versions/2.3.1/bin/ruby(rb_vm_bugreport+0x535) [0x55c2e5985175] vm_dump.c:688<br>
/home/vlad/.rbenv/versions/2.3.1/bin/ruby(rb_bug_context+0xd1) [0x55c2e5961f71] error.c:435<br>
/home/vlad/.rbenv/versions/2.3.1/bin/ruby(sigsegv+0x3e) [0x55c2e585c3ee] signal.c:890<br>
/lib/x86_64-linux-gnu/libpthread.so.0 [0x7fb325847390]<br>
/home/vlad/.rbenv/versions/2.3.1/bin/ruby(autoload_reset+0xa3) [0x55c2e58acd43] variable.c:2129<br>
/home/vlad/.rbenv/versions/2.3.1/bin/ruby(rb_ensure+0xf0) [0x55c2e57991f0] eval.c:906<br>
/home/vlad/.rbenv/versions/2.3.1/bin/ruby(rb_autoload_load+0x156) [0x55c2e58b3156] variable.c:2190<br>
/home/vlad/.rbenv/versions/2.3.1/bin/ruby(rb_const_get_0.constprop.24+0x104) [0x55c2e58b3304] variable.c:2243</p>
</blockquote>
<p>C level backtrace suggests that the issue may be related to autoload.</p>
<p>I found same issue on rails/rails repository. <a href="https://github.com/rails/rails/issues/27455" class="external">https://github.com/rails/rails/issues/27455</a></p>
<p>Here is a reduced script.<br>
This code causes SEGV with a 60-70% possibility as far as I see.</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="nb">sleep</span> <span class="k">if</span> <span class="vg">$load</span>
<span class="vg">$load</span> <span class="o">=</span> <span class="kp">true</span>
<span class="n">n</span> <span class="o">=</span> <span class="mi">10</span>
<span class="n">threads</span> <span class="o">=</span> <span class="no">Array</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="n">n</span><span class="p">)</span> <span class="k">do</span>
<span class="no">Thread</span><span class="p">.</span><span class="nf">new</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="nb">autoload</span> <span class="ss">:Foo</span><span class="p">,</span> <span class="s2">"</span><span class="si">#{</span><span class="no">File</span><span class="p">.</span><span class="nf">dirname</span><span class="p">(</span><span class="vg">$0</span><span class="p">)</span><span class="si">}</span><span class="s2">/</span><span class="si">#{</span><span class="vg">$0</span><span class="si">}</span><span class="s2">"</span>
<span class="no">Thread</span><span class="p">.</span><span class="nf">pass</span>
<span class="no">Foo</span>
<span class="k">ensure</span>
<span class="no">Thread</span><span class="p">.</span><span class="nf">pass</span>
<span class="k">end</span>
<span class="k">end</span>
<span class="k">end</span>
<span class="no">Thread</span><span class="p">.</span><span class="nf">pass</span> <span class="k">while</span> <span class="n">threads</span><span class="p">.</span><span class="nf">all?</span><span class="p">(</span><span class="o">&</span><span class="ss">:stop?</span><span class="p">)</span>
<span class="mi">100</span><span class="p">.</span><span class="nf">times</span> <span class="p">{</span> <span class="no">Thread</span><span class="p">.</span><span class="nf">pass</span> <span class="p">}</span>
</code></pre> Ruby master - Bug #13526: Segmentation fault at 0x0055c2e58e8920 ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]https://bugs.ruby-lang.org/issues/13526?journal_id=646262017-05-01T13:31:20Zusa (Usaku NAKAMURA)usa@garbagecollect.jp
<ul><li><strong>File</strong> <a href="/attachments/6520">segv.log</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/6520/segv.log">segv.log</a> added</li><li><strong>Description</strong> updated (<a title="View differences" href="/journals/64626/diff?detail_id=44944">diff</a>)</li><li><strong>Backport</strong> changed from <i>2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN</i> to <i>2.2: UNKNOWN, 2.3: REQUIRED, 2.4: UNKNOWN</i></li></ul> Ruby master - Bug #13526: Segmentation fault at 0x0055c2e58e8920 ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]https://bugs.ruby-lang.org/issues/13526?journal_id=646272017-05-01T13:33:15Zusa (Usaku NAKAMURA)usa@garbagecollect.jp
<ul></ul><p>It seems that the HEAD of ruby_2_3 still has this problem but trunk nor ruby_2_4 don't.</p> Ruby master - Bug #13526: Segmentation fault at 0x0055c2e58e8920 ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]https://bugs.ruby-lang.org/issues/13526?journal_id=646282017-05-01T14:01:47Zwanabe (_ wanabe)s.wanabe@gmail.com
<ul><li><strong>File</strong> <a href="/attachments/6521">bug13526.log</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/6521/bug13526.log">bug13526.log</a> added</li></ul><p>I'm sorry to reproduce with trunk at my environment.<br>
Log attached.</p> Ruby master - Bug #13526: Segmentation fault at 0x0055c2e58e8920 ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]https://bugs.ruby-lang.org/issues/13526?journal_id=646292017-05-01T20:29:59Zusa (Usaku NAKAMURA)usa@garbagecollect.jp
<ul><li><strong>Backport</strong> changed from <i>2.2: UNKNOWN, 2.3: REQUIRED, 2.4: UNKNOWN</i> to <i>2.2: UNKNOWN, 2.3: REQUIRED, 2.4: REQUIRED</i></li></ul><p>wanabe (_ wanabe) wrote:</p>
<blockquote>
<p>I'm sorry to reproduce with trunk at my environment.</p>
</blockquote>
<p>Oh, thank you.</p> Ruby master - Bug #13526: Segmentation fault at 0x0055c2e58e8920 ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]https://bugs.ruby-lang.org/issues/13526?journal_id=646782017-05-07T02:44:17Zwanabe (_ wanabe)s.wanabe@gmail.com
<ul><li><strong>File</strong> <a href="/attachments/6529">bug13526_dp.log</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/6529/bug13526_dp.log">bug13526_dp.log</a> added</li><li><strong>File</strong> <a href="/attachments/6528">bug13526_dp.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/6528/bug13526_dp.patch">bug13526_dp.patch</a> added</li></ul><p><code>git bisect</code> shows that this issue is appeared at r52332 [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: multi-threaded autoload sometimes fails (Closed)" href="https://bugs.ruby-lang.org/issues/11384">#11384</a>].</p>
<p>I ran <a href="https://bugs.ruby-lang.org/issues/13526#note-1" class="external">https://bugs.ruby-lang.org/issues/13526#note-1</a> script with attached debug-print patch and got the log.</p>
<ol>
<li>Thread 0x000055eacc7089d0 had "waitq: 0x7f737581fa18" on the stack. (line 4)</li>
<li>Thread 0x000055eacc7089d0 was killed and its stack was shrinked. (line 20)</li>
<li>
<code>rb_autoload_reset()</code> tried to delete "waitq: 0x7f737581fa18" from list. (line 22)</li>
<li>But the node have been out of stack and corrupted!</li>
</ol>
<p>And the log alerts us that <code>check_autoload_required()</code> returns inconsistent values.<br>
I guess this is caused by the flow: <code>rb_autoload_str()</code> -> <code>rb_const_set(mod, id, Qundef)</code> -> <code>const_tbl_update()</code> -> <code>autoload_delete()</code> -> <code>st_delete(RCLASS_IV_TBL(mod), &autoload, &val)</code>.<br>
(But maybe other issue...)</p> Ruby master - Bug #13526: Segmentation fault at 0x0055c2e58e8920 ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]https://bugs.ruby-lang.org/issues/13526?journal_id=646802017-05-07T03:51:29Znormalperson (Eric Wong)normalperson@yhbt.net
<ul></ul><p><a href="mailto:s.wanabe@gmail.com" class="email">s.wanabe@gmail.com</a> wrote:</p>
<blockquote>
<p><code>git bisect</code> shows that this issue is appeared at r52332 [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: multi-threaded autoload sometimes fails (Closed)" href="https://bugs.ruby-lang.org/issues/11384">#11384</a>].</p>
<p>I ran <a href="https://bugs.ruby-lang.org/issues/13526#note-1" class="external">https://bugs.ruby-lang.org/issues/13526#note-1</a> script with attached debug-print patch and got the log.</p>
</blockquote>
<p>Thank you! Fix coming.</p> Ruby master - Bug #13526: Segmentation fault at 0x0055c2e58e8920 ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]https://bugs.ruby-lang.org/issues/13526?journal_id=646812017-05-07T04:26:43ZAnonymous
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset trunk|r58587.</p>
<hr>
<p>variable.c: cleanup waitq upon thread death</p>
<ul>
<li>variable.c (autoload_reset): use idempotent list_del_init<br>
(autoload_sleep): moved code from rb_autoload_load<br>
(autoload_sleep_done): cleanup for use with rb_ensure<br>
(rb_autoload_load): ensure list delete happens in case the<br>
thread dies during sleep</li>
<li>test/ruby/bug-13526.rb: new script for separate execution</li>
<li>test/ruby/test_autoload.rb (test_bug_13526): new test<br>
<a href="/issues/13526">[ruby-core:81016]</a> [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Segmentation fault at 0x0055c2e58e8920 ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux] (Closed)" href="https://bugs.ruby-lang.org/issues/13526">#13526</a>]</li>
</ul> Ruby master - Bug #13526: Segmentation fault at 0x0055c2e58e8920 ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]https://bugs.ruby-lang.org/issues/13526?journal_id=646822017-05-07T04:31:49Znormalperson (Eric Wong)normalperson@yhbt.net
<ul></ul><p>Eric Wong <a href="mailto:normalperson@yhbt.net" class="email">normalperson@yhbt.net</a> wrote:</p>
<blockquote>
<p><a href="mailto:s.wanabe@gmail.com" class="email">s.wanabe@gmail.com</a> wrote:</p>
<blockquote>
<p><code>git bisect</code> shows that this issue is appeared at r52332 [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: multi-threaded autoload sometimes fails (Closed)" href="https://bugs.ruby-lang.org/issues/11384">#11384</a>].</p>
<p>I ran <a href="https://bugs.ruby-lang.org/issues/13526#note-1" class="external">https://bugs.ruby-lang.org/issues/13526#note-1</a> script with attached debug-print patch and got the log.</p>
</blockquote>
<p>Thank you! Fix coming.</p>
</blockquote>
<p>OK, committed as r58587 with that script.</p>
<p>Everyone: In the future, feel free to Cc: me regarding any<br>
problems I may have (even tangentially) caused. I am on many<br>
mailing lists so I prioritize stuff I'm Cc-ed on. Thanks.</p> Ruby master - Bug #13526: Segmentation fault at 0x0055c2e58e8920 ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]https://bugs.ruby-lang.org/issues/13526?journal_id=646832017-05-07T05:41:00Zwanabe (_ wanabe)s.wanabe@gmail.com
<ul></ul><p>normalperson (Eric Wong) wrote:</p>
<blockquote>
<p>OK, committed as r58587 with that script.</p>
</blockquote>
<p>Thank you!<br>
It works perfectly as far as I can see.</p>
<blockquote>
<p>Everyone: In the future, feel free to Cc: me regarding any<br>
problems I may have (even tangentially) caused. I am on many<br>
mailing lists so I prioritize stuff I'm Cc-ed on. Thanks.</p>
</blockquote>
<p>Sorry. I've commented by Redmine with my web browser, so I could not Cc: you.<br>
So I add you as the watcher. Does Redmine Cc this comment to you?</p> Ruby master - Bug #13526: Segmentation fault at 0x0055c2e58e8920 ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]https://bugs.ruby-lang.org/issues/13526?journal_id=646842017-05-07T06:02:52Znormalperson (Eric Wong)normalperson@yhbt.net
<ul></ul><p><a href="mailto:s.wanabe@gmail.com" class="email">s.wanabe@gmail.com</a> wrote:</p>
<blockquote>
<p>normalperson (Eric Wong) wrote:</p>
<blockquote>
<p>OK, committed as r58587 with that script.</p>
</blockquote>
<p>Thank you!<br>
It works perfectly as far as I can see.</p>
</blockquote>
<p>Thank you for confirming. Your small reproduction script was<br>
very helpful.</p>
<blockquote>
<blockquote>
<p>Everyone: In the future, feel free to Cc: me regarding any<br>
problems I may have (even tangentially) caused. I am on many<br>
mailing lists so I prioritize stuff I'm Cc-ed on. Thanks.</p>
</blockquote>
<p>Sorry. I've commented by Redmine with my web browser, so I could not Cc: you.<br>
So I add you as the watcher. Does Redmine Cc this comment to you?</p>
</blockquote>
<p>Yes, adding as redmine watcher works for me. Thanks.</p> Ruby master - Bug #13526: Segmentation fault at 0x0055c2e58e8920 ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]https://bugs.ruby-lang.org/issues/13526?journal_id=647252017-05-09T15:42:56Znagachika (Tomoyuki Chikanaga)nagachika00@gmail.com
<ul><li><strong>Backport</strong> changed from <i>2.2: UNKNOWN, 2.3: REQUIRED, 2.4: REQUIRED</i> to <i>2.2: UNKNOWN, 2.3: REQUIRED, 2.4: DONE</i></li></ul><p>ruby_2_4 r58637 merged revision(s) 58587,58588.</p> Ruby master - Bug #13526: Segmentation fault at 0x0055c2e58e8920 ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]https://bugs.ruby-lang.org/issues/13526?journal_id=655732017-06-30T10:52:07Zusa (Usaku NAKAMURA)usa@garbagecollect.jp
<ul><li><strong>Backport</strong> changed from <i>2.2: UNKNOWN, 2.3: REQUIRED, 2.4: DONE</i> to <i>2.2: UNKNOWN, 2.3: DONE, 2.4: DONE</i></li></ul><p>ruby_2_3 r59219 merged revision(s) 58587,58588.</p> Ruby master - Bug #13526: Segmentation fault at 0x0055c2e58e8920 ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]https://bugs.ruby-lang.org/issues/13526?journal_id=678552017-11-19T15:22:15ZEregon (Benoit Daloze)
<ul></ul><p>Note that the original example only works if it's a file under the current directory invoked like "ruby test.rb",<br>
Otherwise <code>"#{File.dirname($0)}/#{$0}"</code> does not refer to the current file.<br>
I fixed it in r60854, to use <code>File.expand_path(__FILE__)</code>.</p>
<p>The bug still happens on 2.4.1 whether the file exists or not, so it seems fine to test the case where the file does exist.<br>
The bug seems caused by the interaction of autoload threads and the shutdown triggered by the main thread.</p>