1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/timeout] Explicit add the timeout thread to default ThreadGroup

Otherwise the timeout thread would be added to the ThreadGroup of the thread that makes the first call to Timeout.timeout .

Fixes bug 19020: https://bugs.ruby-lang.org/issues/19020

Add a test case to make sure the common thread doesn't leak to another ThreadGroup

https://github.com/ruby/timeout/commit/c4f1385c9a
This commit is contained in:
Lars Kanis 2022-09-25 11:14:11 +02:00 committed by git
parent 1a06bc94d9
commit 9d56d9975d
2 changed files with 14 additions and 0 deletions

View file

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

View file

@ -159,4 +159,17 @@ class TestTimeout < Test::Unit::TestCase
assert_equal 'timeout', r.read assert_equal 'timeout', r.read
r.close r.close
end end
def test_threadgroup
assert_separately(%w[-rtimeout], <<-'end;')
tg = ThreadGroup.new
thr = Thread.new do
tg.add(Thread.current)
Timeout.timeout(10){}
end
thr.join
assert_equal [].to_s, tg.list.to_s
end;
end
end end