Skip to content

Commit 05459d1

Browse files
committed
vm_trace.c: defer interrupts while postponed jobs
* vm_trace.c (rb_postponed_job_flush): mask signal trap interrupt too to defer handling after finalizers finished. [ruby-core:66825] [Bug #10595] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48829 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 6447d06 commit 05459d1

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Sat Dec 13 20:41:55 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
2+
3+
* vm_trace.c (rb_postponed_job_flush): mask signal trap interrupt
4+
too to defer handling after finalizers finished.
5+
[ruby-core:66825] [Bug #10595]
6+
17
Sat Dec 13 18:33:25 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
28

39
* test/openssl/test_pkey_ec.rb: ignored tests with old OpenSSL.

test/ruby/test_gc.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,32 @@ def test_exception_in_finalizer
331331
end;
332332
end
333333

334+
def test_interrupt_in_finalizer
335+
bug10595 = '[ruby-core:66825] [Bug #10595]'
336+
src = <<-'end;'
337+
f = proc {1000.times {}}
338+
loop do
339+
ObjectSpace.define_finalizer(Object.new, f)
340+
end
341+
end;
342+
error = nil
343+
status = nil
344+
EnvUtil.invoke_ruby(["-e", src], "", false, true) do |_, _, stderr, pid|
345+
sleep 0.1
346+
Process.kill("INT", pid)
347+
th = Thread.start do
348+
sleep 1
349+
Process.kill("KILL", pid) rescue nil
350+
end
351+
error = stderr.read
352+
_, status = Process.wait2(pid)
353+
th.kill
354+
end
355+
assert_predicate status, :signaled?
356+
assert_equal "INT", Signal.signame(status.termsig), bug10595
357+
assert_match /Interrupt/, error, bug10595
358+
end
359+
334360
def test_verify_internal_consistency
335361
assert_nil(GC.verify_internal_consistency)
336362
end

vm_trace.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,12 +1554,13 @@ void
15541554
rb_postponed_job_flush(rb_vm_t *vm)
15551555
{
15561556
rb_thread_t *th = GET_THREAD();
1557-
unsigned long saved_postponed_job_interrupt_mask = th->interrupt_mask & POSTPONED_JOB_INTERRUPT_MASK;
1557+
const unsigned long block_mask = POSTPONED_JOB_INTERRUPT_MASK|TRAP_INTERRUPT_MASK;
1558+
unsigned long saved_mask = th->interrupt_mask & block_mask;
15581559
VALUE saved_errno = th->errinfo;
15591560

15601561
th->errinfo = Qnil;
15611562
/* mask POSTPONED_JOB dispatch */
1562-
th->interrupt_mask |= POSTPONED_JOB_INTERRUPT_MASK;
1563+
th->interrupt_mask |= block_mask;
15631564
{
15641565
TH_PUSH_TAG(th);
15651566
EXEC_TAG();
@@ -1575,6 +1576,6 @@ rb_postponed_job_flush(rb_vm_t *vm)
15751576
TH_POP_TAG();
15761577
}
15771578
/* restore POSTPONED_JOB mask */
1578-
th->interrupt_mask &= ~(saved_postponed_job_interrupt_mask ^ POSTPONED_JOB_INTERRUPT_MASK);
1579+
th->interrupt_mask &= ~(saved_mask ^ block_mask);
15791580
th->errinfo = saved_errno;
15801581
}

0 commit comments

Comments
 (0)