https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112019-03-28T22:42:11ZRuby Issue Tracking SystemRuby master - Bug #15735: Thread#handle_interrupt does not prevent Thread#kill from interruptinghttps://bugs.ruby-lang.org/issues/15735?journal_id=773612019-03-28T22:42:11ZEregon (Benoit Daloze)
<ul></ul><p>If that is the case, that might also mean the fix in <a href="https://bugs.ruby-lang.org/issues/14998" class="external">https://bugs.ruby-lang.org/issues/14998</a> might not be sufficient.</p> Ruby master - Bug #15735: Thread#handle_interrupt does not prevent Thread#kill from interruptinghttps://bugs.ruby-lang.org/issues/15735?journal_id=913902021-04-08T15:01:02Zjeremyevans (Jeremy Evans)code@jeremyevans.net
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset <a class="changeset" title="Document how to handle kill/terminate interrupts in Thread.handle_interrupt The kill/terminate i..." href="https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/5c4ff3f00c6bd84ef0721c1077ee9c525daa68f8">git|5c4ff3f00c6bd84ef0721c1077ee9c525daa68f8</a>.</p>
<hr>
<p>Document how to handle kill/terminate interrupts in Thread.handle_interrupt</p>
<p>The kill/terminate interrupts are internally handled not as Exception<br>
instances, but as integers. So using Exception doesn't handle these<br>
interrupts, but Object does. You can use Integer if you only want to<br>
handle kill/terminate interrupts, but that's probably more of an<br>
implementation detail, while handling Object should work regardless<br>
of the implementation.</p>
<p>Fixes [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Thread#handle_interrupt does not prevent Thread#kill from interrupting (Closed)" href="https://bugs.ruby-lang.org/issues/15735">#15735</a>]</p> Ruby master - Bug #15735: Thread#handle_interrupt does not prevent Thread#kill from interruptinghttps://bugs.ruby-lang.org/issues/15735?journal_id=913912021-04-08T15:11:29Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul></ul><p>I've determined this is just a documentation issue, and there is a way for <code>Thread.handle_interrupt</code> to handle kill/terminate interrupts, which I've committed.</p>
<p>If we handle to allow <code>Exception</code> to include these interrupts, we could do something like this:</p>
<pre><code class="diff syntaxhl" data-language="diff"><span class="gd">--- a/thread.c
</span><span class="gi">+++ b/thread.c
</span><span class="p">@@ -1992,6 +1992,7 @@</span> rb_threadptr_pending_interrupt_check_mask(rb_thread_t *th, VALUE err)
VALUE mod;
long i;
<span class="err">
</span><span class="gi">+ retry:
</span> for (i=0; i<mask_stack_len; i++) {
mask = mask_stack[mask_stack_len-(i+1)];
<span class="err">
</span><span class="p">@@ -2023,6 +2024,15 @@</span> rb_threadptr_pending_interrupt_check_mask(rb_thread_t *th, VALUE err)
}
/* try to next mask */
}
<span class="gi">+
+ /* eKillSignal and eTerminateSignal are Integers, but should be
+ * rescued if using Exception in Thread.handle_interrupt.
+ */
+ if (err == rb_cInteger) {
+ err = rb_eException;
+ goto retry;
+ }
+
</span> return INTERRUPT_NONE;
}
<span class="err">
</span></code></pre>