Actions
Bug #19480
closedinvalid keeping_mutexes: Attempt to unlock a mutex which is not locked with fiber scheduler.
Description
The following program has a race condition due to IO write locks:
#!/usr/bin/env ruby
require_relative 'lib/async'
def wait_for_interrupt(thread_index, repeat)
sequence = []
events = Thread::Queue.new
reactor = Async::Reactor.new
thread = Thread.new do
if events.pop
puts "#{thread_index}+#{repeat} Sending Interrupt!"
reactor.interrupt
end
end
reactor.async do
events << true
puts "#{thread_index}+#{repeat} Reactor ready!"
# Wait to be interrupted:
sleep(1)
puts "#{thread_index}+#{repeat} Missing interrupt!"
end
reactor.run
thread.join
end
64.times.map do |thread_index|
Thread.new do
1000.times do |repeat|
wait_for_interrupt(thread_index, repeat)
end
end
end.each(&:join)
The error manifests:
58+407 Reactor ready!
58+407 Sending Interrupt!
46+396 Sending Interrupt!
58+408 Sending Interrupt!
46+397 Reactor ready!
#<Thread:0x00007f9f681ca8e0 ./test-segfault.rb:11 run> terminated with exception (report_on_exception is true):
52+425 Sending Interrupt!
/home/samuel/Projects/socketry/async/lib/async/scheduler.rb:131:in `unblock': undefined method `wakeup' for nil:NilClass (NoMethodError)
@selector.wakeup
^^^^^^^
from ./test-segfault.rb:13:in `write'
from ./test-segfault.rb:13:in `puts'
from ./test-segfault.rb:13:in `puts'
from ./test-segfault.rb:13:in `block in wait_for_interrupt'
[BUG] invalid keeping_mutexes: Attempt to unlock a mutex which is not locked
ruby 3.2.1 (2023-02-08 revision 31819e82c8) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0001 p:---- s:0003 e:000002 DUMMY [FINISH]
-- C level backtrace information -------------------------------------------
/home/samuel/.rubies/ruby-3.2.1/bin/ruby(rb_print_backtrace+0xd) [0x560fabaeff41] /home/samuel/src/ruby-3.2.1/vm_dump.c:785
/home/samuel/.rubies/ruby-3.2.1/bin/ruby(rb_vm_bugreport) /home/samuel/src/ruby-3.2.1/vm_dump.c:1080
/home/samuel/.rubies/ruby-3.2.1/bin/ruby(bug_report_end+0x0) [0x560fabca13ab] /home/samuel/src/ruby-3.2.1/error.c:790
/home/samuel/.rubies/ruby-3.2.1/bin/ruby(rb_bug_without_die) /home/samuel/src/ruby-3.2.1/error.c:790
/home/samuel/.rubies/ruby-3.2.1/bin/ruby(die+0x0) [0x560fab8d73b8] /home/samuel/src/ruby-3.2.1/error.c:798
/home/samuel/.rubies/ruby-3.2.1/bin/ruby(rb_bug) /home/samuel/src/ruby-3.2.1/error.c:800
/home/samuel/.rubies/ruby-3.2.1/bin/ruby(thread_start_func_2+0x630) [0x560faba84fa0] /home/samuel/src/ruby-3.2.1/thread.c:434
/home/samuel/.rubies/ruby-3.2.1/bin/ruby(thread_start_func_1+0xdb) [0x560faba857ab] /home/samuel/src/ruby-3.2.1/thread_pthread.c:1170
/usr/lib/libc.so.6(0x7f9f78321bb5) [0x7f9f78321bb5]
/usr/lib/libc.so.6(0x7f9f783a3d90) [0x7f9f783a3d90]
Actions
Like0
Like0Like0