Skip to content

Commit ced3336

Browse files
committed
fix SEGV on clang-16/18
Maybe because of TLS/coroutine problem, CI fails on clang-16/18 ``` 1) Failure: TestTimeout#test_ractor [/tmp/ruby/src/trunk_clang_18/test/test_timeout.rb:288]: pid 307341 killed by SIGSEGV (signal 11) (core dumped) | /tmp/ruby/src/trunk_clang_18/lib/timeout.rb:98: [BUG] Segmentation fault at 0x0000000000000030 | ruby 4.0.0dev (2025-12-07T16:51:02Z master 4f900c3) +PRISM [x86_64-linux] | | -- Control frame information ----------------------------------------------- | c:0006 p:---- s:0026 e:000025 l:y b:---- CFUNC :sleep | c:0005 p:---- s:0023 e:000022 l:y b:---- CFUNC :wait | c:0004 p:0020 s:0017 e:000016 l:n b:---- BLOCK /tmp/ruby/src/trunk_clang_18/lib/timeout.rb:98 [FINISH] | c:0003 p:---- s:0014 e:000013 l:y b:---- CFUNC :synchronize | c:0002 p:0072 s:0010 e:000009 l:n b:---- BLOCK /tmp/ruby/src/trunk_clang_18/lib/timeout.rb:96 [FINISH] | c:0001 p:---- s:0003 e:000002 l:y b:---- DUMMY [FINISH] | | -- Ruby level backtrace information ---------------------------------------- | /tmp/ruby/src/trunk_clang_18/lib/timeout.rb:96:in 'block in create_timeout_thread' | /tmp/ruby/src/trunk_clang_18/lib/timeout.rb:96:in 'synchronize' | /tmp/ruby/src/trunk_clang_18/lib/timeout.rb:98:in 'block (2 levels) in create_timeout_thread' | /tmp/ruby/src/trunk_clang_18/lib/timeout.rb:98:in 'wait' | /tmp/ruby/src/trunk_clang_18/lib/timeout.rb:98:in 'sleep' | | -- Threading information --------------------------------------------------- | Total ractor count: 3 | Ruby thread count for this ractor: 2 | | -- Machine register context ------------------------------------------------ | RIP: 0x0000602b1e08a5b5 RBP: 0x000071c65facd130 RSP: 0x000071c6258842e0 | RAX: 0x0000000000000000 RBX: 0x000000006935f7c4 RCX: 0x0000000000000000 | RDX: 0x0000602b1e520c20 RDI: 0x000071c620012480 RSI: 0x000071c620012480 | R8: 0x0000000000000000 R9: 0x0000000000000000 R10: 0x0000000000000000 | R11: 0x0000000000000000 R12: 0x000071c65fa2f640 R13: 0x000071c65fb66e48 | R14: 0x0000000000000000 R15: 0xfdccaa3270000002 EFL: 0x0000000000010202 | | -- C level backtrace information ------------------------------------------- | /tmp/ruby/build/trunk_clang_18/ruby(rb_print_backtrace+0x14) [0x602b1e31a6ea] /tmp/ruby/src/trunk_clang_18/vm_dump.c:1105 | /tmp/ruby/build/trunk_clang_18/ruby(rb_vm_bugreport) /tmp/ruby/src/trunk_clang_18/vm_dump.c:1450 | /tmp/ruby/build/trunk_clang_18/ruby(rb_bug_for_fatal_signal+0x15c) [0x602b1e2d960c] /tmp/ruby/src/trunk_clang_18/error.c:1131 | /tmp/ruby/build/trunk_clang_18/ruby(sigsegv+0x5a) [0x602b1e05528a] /tmp/ruby/src/trunk_clang_18/signal.c:948 | /lib/x86_64-linux-gnu/libc.so.6(0x71c65fd46320) [0x71c65fd46320] | /tmp/ruby/build/trunk_clang_18/ruby(vm_check_ints_blocking+0x0) [0x602b1e08a5b5] /tmp/ruby/src/trunk_clang_18/vm_core.h:2097 | /tmp/ruby/build/trunk_clang_18/ruby(rb_current_execution_context) /tmp/ruby/src/trunk_clang_18/thread_sync.c:617 | /tmp/ruby/build/trunk_clang_18/ruby(rb_mutex_sleep) /tmp/ruby/src/trunk_clang_18/thread_sync.c:617 ``` This patch introduces workaround by acquiring EC before swithcing coroutine.
1 parent 1de1581 commit ced3336

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

thread_sync.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,8 @@ mutex_sleep_begin(VALUE _arguments)
599599
VALUE
600600
rb_mutex_sleep(VALUE self, VALUE timeout)
601601
{
602+
rb_execution_context_t *ec = GET_EC();
603+
602604
if (!NIL_P(timeout)) {
603605
// Validate the argument:
604606
rb_time_interval(timeout);
@@ -614,7 +616,7 @@ rb_mutex_sleep(VALUE self, VALUE timeout)
614616

615617
VALUE woken = rb_ensure(mutex_sleep_begin, (VALUE)&arguments, mutex_lock_uninterruptible, self);
616618

617-
RUBY_VM_CHECK_INTS_BLOCKING(GET_EC());
619+
RUBY_VM_CHECK_INTS_BLOCKING(ec);
618620
if (!woken) return Qnil;
619621
time_t end = time(0) - beg;
620622
return TIMET2NUM(end);

0 commit comments

Comments
 (0)