Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Allow wakeup mutex to be used in trap context. #13684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2025

Conversation

ioquatix
Copy link
Member

@ioquatix ioquatix commented Jun 24, 2025

Fixes this issue:

-- Control frame information -----------------------------------------------
c:0012 p:---- s:0061 e:000060 CFUNC  :write
c:0011 p:---- s:0058 e:000057 CFUNC  :<<
c:0010 p:0007 s:0053 e:000052 METHOD /Users/samuel/Developer/ioquatix/puma/lib/puma/server.rb:615
c:0009 p:0009 s:0047 e:000046 METHOD /Users/samuel/Developer/ioquatix/puma/lib/puma/server.rb:633
c:0008 p:0034 s:0042 e:000041 BLOCK  /Users/samuel/Developer/ioquatix/puma/lib/puma/cluster/worker.rb:106 [FINISH]
c:0007 p:---- s:0039 e:000038 CFUNC  :join
c:0006 p:0359 s:0035 E:001630 METHOD /Users/samuel/Developer/ioquatix/puma/lib/puma/cluster/worker.rb:146
c:0005 p:0044 s:0023 e:000022 BLOCK  /Users/samuel/Developer/ioquatix/puma/lib/puma/cluster/worker.rb:169 [FINISH]
c:0004 p:---- s:0019 e:000018 CFUNC  :fork
c:0003 p:0020 s:0015 e:000014 METHOD /Users/samuel/Developer/ioquatix/puma/lib/puma/cluster/worker.rb:162
c:0002 p:0117 s:0009 e:000007 BLOCK  /Users/samuel/Developer/ioquatix/puma/lib/puma/cluster/worker.rb:96 [FINISH]
c:0001 p:---- s:0003 e:000002 DUMMY  [FINISH]

-- Ruby level backtrace information ----------------------------------------
/Users/samuel/Developer/ioquatix/puma/lib/puma/cluster/worker.rb:96:in 'block in run'
/Users/samuel/Developer/ioquatix/puma/lib/puma/cluster/worker.rb:162:in 'spawn_worker'
/Users/samuel/Developer/ioquatix/puma/lib/puma/cluster/worker.rb:162:in 'fork'
/Users/samuel/Developer/ioquatix/puma/lib/puma/cluster/worker.rb:169:in 'block in spawn_worker'
/Users/samuel/Developer/ioquatix/puma/lib/puma/cluster/worker.rb:146:in 'run'
/Users/samuel/Developer/ioquatix/puma/lib/puma/cluster/worker.rb:146:in 'join'
/Users/samuel/Developer/ioquatix/puma/lib/puma/cluster/worker.rb:106:in 'block in run'
/Users/samuel/Developer/ioquatix/puma/lib/puma/server.rb:633:in 'stop'
/Users/samuel/Developer/ioquatix/puma/lib/puma/server.rb:615:in 'notify_safely'
/Users/samuel/Developer/ioquatix/puma/lib/puma/server.rb:615:in '<<'
/Users/samuel/Developer/ioquatix/puma/lib/puma/server.rb:615:in 'write'

-- Threading information ---------------------------------------------------
Total ractor count: 1
Ruby thread count for this ractor: 6

-- C level backtrace information -------------------------------------------
/Users/samuel/.rubies/ruby-head/bin/ruby(rb_vm_bugreport+0xb74) [0x1045e5084]
/Users/samuel/.rubies/ruby-head/bin/ruby(rb_bug_without_die_internal+0x108) [0x104415204]
/Users/samuel/.rubies/ruby-head/bin/ruby(rb_bug+0x1c) [0x104739514]
/Users/samuel/.rubies/ruby-head/bin/ruby(do_mutex_lock.cold.2+0x0) [0x10473d5dc]
/Users/samuel/.rubies/ruby-head/bin/ruby(rb_mutex_owned_p+0x0) [0x10457dc28]
/Users/samuel/.rubies/ruby-head/bin/ruby(rb_thread_io_blocking_call+0x404) [0x104580adc]
/Users/samuel/.rubies/ruby-head/bin/ruby(rb_io_write_memory+0xa4) [0x104466968]
/Users/samuel/.rubies/ruby-head/bin/ruby(io_binwrite_string+0xa0) [0x104466684]
/Users/samuel/.rubies/ruby-head/bin/ruby(rb_ensure+0xb4) [0x104421358]
/Users/samuel/.rubies/ruby-head/bin/ruby(io_binwrite+0x154) [0x104455028]
/Users/samuel/.rubies/ruby-head/bin/ruby(io_write+0x15c) [0x10446b578]
/Users/samuel/.rubies/ruby-head/bin/ruby(vm_call0_body+0x388) [0x1045dbec4]
/Users/samuel/.rubies/ruby-head/bin/ruby(rb_funcallv_scope+0x250) [0x1045c5190]
/Users/samuel/.rubies/ruby-head/bin/ruby(rb_io_addstr+0x3c) [0x1044550e0]
/Users/samuel/.rubies/ruby-head/bin/ruby(vm_call_cfunc_with_frame_+0xf0) [0x1045d6368]
/Users/samuel/.rubies/ruby-head/bin/ruby(vm_exec_core+0x4298) [0x1045bcaec]
/Users/samuel/.rubies/ruby-head/bin/ruby(rb_vm_exec+0x1b0) [0x1045b749c]
/Users/samuel/.rubies/ruby-head/bin/ruby(vm_invoke_proc+0x2b8) [0x1045ca864]
/Users/samuel/.rubies/ruby-head/bin/ruby(vm_call0_body+0x7c0) [0x1045dc2fc]
/Users/samuel/.rubies/ruby-head/bin/ruby(rb_call0+0x360) [0x1045dd2d0]
/Users/samuel/.rubies/ruby-head/bin/ruby(rb_eval_cmd_kw+0x188) [0x1045c7154]
/Users/samuel/.rubies/ruby-head/bin/ruby(signal_exec+0x108) [0x10453b06c]
/Users/samuel/.rubies/ruby-head/bin/ruby(rb_threadptr_execute_interrupts+0x204) [0x104580f80]
/Users/samuel/.rubies/ruby-head/bin/ruby(thread_join_sleep+0x2b0) [0x10458b850]
/Users/samuel/.rubies/ruby-head/bin/ruby(rb_ensure+0xb4) [0x104421358]
/Users/samuel/.rubies/ruby-head/bin/ruby(thread_join+0xb4) [0x10458b4d0]
/Users/samuel/.rubies/ruby-head/bin/ruby(thread_join_m+0xe8) [0x104586004]
/Users/samuel/.rubies/ruby-head/bin/ruby(vm_call_cfunc_with_frame_+0xf0) [0x1045d6368]
/Users/samuel/.rubies/ruby-head/bin/ruby(vm_exec_core+0x4298) [0x1045bcaec]
/Users/samuel/.rubies/ruby-head/bin/ruby(rb_vm_exec+0x35c) [0x1045b7648]
/Users/samuel/.rubies/ruby-head/bin/ruby(invoke_block_from_c_bh+0x370) [0x1045dea40]
/Users/samuel/.rubies/ruby-head/bin/ruby(rb_yield+0xc0) [0x1045c5b98]
/Users/samuel/.rubies/ruby-head/bin/ruby(rb_protect+0xb8) [0x1044211f8]
/Users/samuel/.rubies/ruby-head/bin/ruby(rb_f_fork+0x90) [0x1044e561c]
/Users/samuel/.rubies/ruby-head/bin/ruby(vm_call_cfunc_with_frame_+0xf0) [0x1045d6368]
/Users/samuel/.rubies/ruby-head/bin/ruby(vm_exec_core+0x18c4) [0x1045ba118]
/Users/samuel/.rubies/ruby-head/bin/ruby(rb_vm_exec+0x1b0) [0x1045b749c]
/Users/samuel/.rubies/ruby-head/bin/ruby(vm_invoke_proc+0x2b8) [0x1045ca864]
/Users/samuel/.rubies/ruby-head/bin/ruby(thread_do_start_proc+0x2d0) [0x104588a64]
/Users/samuel/.rubies/ruby-head/bin/ruby(thread_start_func_2+0x30c) [0x104587ee0]
/Users/samuel/.rubies/ruby-head/bin/ruby(nt_start+0xf4) [0x10458a644]
/usr/lib/system/libsystem_pthread.dylib(_pthread_start+0x88) [0x19e266c0c]

Copy link

Tests Failed

✖️no tests failed ✔️62033 tests passed(2 flakes)

@ioquatix ioquatix merged commit ba68343 into ruby:master Jun 24, 2025
88 of 90 checks passed
@ko1
Copy link
Contributor

ko1 commented Jun 24, 2025

please write [BUG] line. Without it, we can't understand what is the problem.

@ioquatix ioquatix deleted the allow-wakeup_mutex-trap-context branch June 24, 2025 06:06
@ioquatix
Copy link
Member Author

@ko1 The linked issues explain the problem with a reproduction. IO#close, which might be happening while a signal is invoked, can cause IO#write to lock the wakeup_mutex.

Personally, I'd like us to address #13545 but I'm still waiting on your review/feedback.

@ko1
Copy link
Contributor

ko1 commented Jun 24, 2025

I wrote it for general idea. Please do not forget [BUG] ... line.

@ioquatix
Copy link
Member Author

@ko1 I misunderstood your request. This is not an actual rb_bug, but I replaced rb_raise with rb_bug to get C stack trace, which shows the problem. The bug line would be similar to as the issue title for the Puma issue 'IO#write': can't be called from trap context. Unfortunately, I no longer have that output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants