Project

General

Profile

Actions

Bug #19020

closed

Unexpected timeout thread appears in ThreadGroup

Added by larskanis (Lars Kanis) 2 months ago. Updated 2 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 3.2.0dev (2022-09-23T20:17:54Z master 912ea8257a) [x86_64-linux]
[ruby-core:110053]

Description

The new timeout implementation creates a thread at the very first use.
This has the side effect, that this management thread appears in a surrounding ThreadGroup.
See this example:

require "timeout"

threadgroup = ThreadGroup.new
thr = Thread.new do
  Timeout.timeout(10){}
end
threadgroup.add(thr)
p after_add: threadgroup, list: threadgroup.list

sleep 0.2
p after_sleep: threadgroup, list: threadgroup.list

On ruby master branch the ThreadGroup lists this common management thread of the timeout library:

$ ruby test-threadgroup.rb
{:after_add=>#<ThreadGroup:0x00007f12f120adb8>, :list=>[#<Thread:0x00007f12f120acc8 test-threadgroup.rb:4 run>]}
{:after_sleep=>#<ThreadGroup:0x00007f12f120adb8>, :list=>[#<Thread:0x00007f12f120a1d8@Timeout stdlib thread /home/lars/.rvm/rubies/ruby-head/lib/ruby/3.2.0+2/timeout.rb:101 sleep_forever>]}

While older ruby versions don't show any timeout thread:

$ ruby test-threadgroup.rb
{:after_add=>#<ThreadGroup:0x0000556315b26b50>, :list=>[#<Thread:0x0000556315b26b28@test-threadgroup.rb:4 run>]}
{:after_sleep=>#<ThreadGroup:0x0000556315b26b50>, :list=>[]}
Actions

Also available in: Atom PDF

Like0
Like0Like0