-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid race conditions in
Scheduler#unblock
.
See <ruby/ruby#7460> for more details.
- Loading branch information
Showing
4 changed files
with
114 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env ruby | ||
|
||
# This bug only generally shows up on Linux, when using io_uring, as it has more fine-grained locking. The issue is that `puts` can acquire and release a write lock, and if one thread releases that lock while the reactor on the waitq thread is closing, it can call `unblock` with `@selector = nil` which fails or causes odd behaviour. | ||
|
||
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 | ||
|
||
100.times.map do |thread_index| | ||
Thread.new do | ||
1000.times do |repeat| | ||
wait_for_interrupt(thread_index, repeat) | ||
end | ||
end | ||
end.each(&:join) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/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 | ||
|
||
32.times.map do |thread_index| | ||
Thread.new do | ||
100.times do |repeat| | ||
wait_for_interrupt(thread_index, repeat) | ||
end | ||
end | ||
end.each(&:join) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters