Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't move the timer_thread when it's enclosed #24 #25

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion lib/timeout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions test/test_timeout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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