[前][次][番号順一覧][スレッド一覧]

ruby-changes:73748

From: Lars <ko1@a...>
Date: Wed, 28 Sep 2022 01:59:48 +0900 (JST)
Subject: [ruby-changes:73748] 9d56d9975d (master): [ruby/timeout] Explicit add the timeout thread to default ThreadGroup

https://git.ruby-lang.org/ruby.git/commit/?id=9d56d9975d

From 9d56d9975d867c94ab2a6d76e4482112ab6c3319 Mon Sep 17 00:00:00 2001
From: Lars Kanis <lars@g...>
Date: Sun, 25 Sep 2022 11:14:11 +0200
Subject: [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
---
 lib/timeout.rb       |  1 +
 test/test_timeout.rb | 13 +++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/lib/timeout.rb b/lib/timeout.rb
index 2aad1d7465..badba9a397 100644
--- a/lib/timeout.rb
+++ b/lib/timeout.rb
@@ -120,6 +120,7 @@ module Timeout https://github.com/ruby/ruby/blob/trunk/lib/timeout.rb#L120
         requests.reject!(&:done?)
       end
     end
+    ThreadGroup::Default.add(watcher)
     watcher.name = "Timeout stdlib thread"
     watcher.thread_variable_set(:"\0__detached_thread__", true)
     watcher
diff --git a/test/test_timeout.rb b/test/test_timeout.rb
index 76de38949d..2d3dd16245 100644
--- a/test/test_timeout.rb
+++ b/test/test_timeout.rb
@@ -159,4 +159,17 @@ class TestTimeout < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/test_timeout.rb#L159
     assert_equal 'timeout', r.read
     r.close
   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
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]