diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7465b8a..0071eb1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ jobs: strategy: fail-fast: false matrix: - ruby: [ '3.2', '3.1', '3.0', '2.7', head, jruby, truffleruby-head ] + ruby: [ '3.2', '3.1', '3.0', '2.7', head, jruby, truffleruby, truffleruby-head ] os: [ ubuntu-latest, macos-latest ] runs-on: ${{ matrix.os }} steps: diff --git a/lib/timeout.rb b/lib/timeout.rb index 7f40baf..1d092f7 100644 --- a/lib/timeout.rb +++ b/lib/timeout.rb @@ -120,7 +120,7 @@ def self.create_timeout_thread 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 diff --git a/test/test_timeout.rb b/test/test_timeout.rb index 2d3dd16..c3349d0 100644 --- a/test/test_timeout.rb +++ b/test/test_timeout.rb @@ -172,4 +172,17 @@ def test_threadgroup end; end + # https://github.com/ruby/timeout/issues/24 + def test_handling_enclosed_threadgroup + assert_separately(%w[-rtimeout], <<-'end;') + Thread.new { + t = Thread.current + group = ThreadGroup.new + group.add(t) + group.enclose + + assert_equal 42, Timeout.timeout(1) { 42 } + }.join + end; + end end