[ruby/timeout] Don't move the timer_thread when it's enclosed

Don't move the timer_thread to ThreadGroup::Default, when it's
created in an enclosed ThreadGroup.
Prevents the exception: "add" can't move from the enclosed thread group"

https://github.com/ruby/timeout/commit/eb889d2c8b
This commit is contained in:
Rick Blommers 2023-02-12 15:23:37 +01:00 коммит произвёл git
Родитель 8943b0d411
Коммит 610375edfc
2 изменённых файлов: 20 добавлений и 1 удалений

Просмотреть файл

@ -120,7 +120,7 @@ module Timeout
requests.reject!(&:done?)
end
end
ThreadGroup::Default.add(watcher)
ThreadGroup::Default.add(watcher) unless watcher.group.enclosed?
watcher.name = "Timeout stdlib thread"
watcher.thread_variable_set(:"\0__detached_thread__", true)
watcher

Просмотреть файл

@ -172,4 +172,23 @@ class TestTimeout < Test::Unit::TestCase
end;
end
def test_handling_enclosed_threadgroup
# The problem "add: can't move from the enclosed thread group" #24,
# happens when the timeout_thread is created in an enclosed ThreadGroup.
assert_separately(%w[-rtimeout], <<-'end;')
t1 = Thread.new {
Thread.stop
assert_block do
Timeout.timeout(0.1) {}
true
end
}
sleep 0.1 while t1.status != 'sleep'
group = ThreadGroup.new
group.add(t1)
group.enclose
t1.run
t1.join
end;
end
end