Skip to content

Don't clear the ThreadGroup when Thread terminates#8425

Merged
headius merged 1 commit intojruby:masterfrom
headius:no_clear_threadgroup_in_thread_dispose
Nov 14, 2024
Merged

Don't clear the ThreadGroup when Thread terminates#8425
headius merged 1 commit intojruby:masterfrom
headius:no_clear_threadgroup_in_thread_dispose

Conversation

@headius
Copy link
Member

@headius headius commented Nov 14, 2024

CRuby does not clear the ThreadGroup set in the Thread when the thread terminates. We do, which leads to some unpredictability in specs that check the group against a very short-lived thread. This patch removes the call to clear the thread's group.

CRuby does not clear the ThreadGroup set in the Thread when the
thread terminates. We do, which leads to some unpredictability in
specs that check the group against a very short-lived thread. This
patch removes the call to clear the thread's group.
@headius headius added this to the JRuby 9.4.10.0 milestone Nov 14, 2024
@headius headius marked this pull request as ready for review November 14, 2024 20:35
@headius
Copy link
Member Author

headius commented Nov 14, 2024

The failure is intermittent but looks like this:

1)
Thread#group returns the thread group explicitly set for this thread FAILED
Expected nil == #<ThreadGroup:0x29d8d547>
to be truthy but was false
/home/runner/work/jruby/jruby/spec/ruby/core/thread/group_spec.rb:12:in `block in <main>'
org/jruby/RubyBasicObject.java:2655:in `instance_exec'
org/jruby/RubyArray.java:4910:in `all?'
org/jruby/RubyArray.java:1981:in `each'
/home/runner/work/jruby/jruby/spec/ruby/core/thread/group_spec.rb:3:in `<main>'
org/jruby/RubyKernel.java:1223:in `load'
org/jruby/RubyBasicObject.java:2655:in `instance_exec'
org/jruby/RubyArray.java:1981:in `each'

It's because in this code, sometimes the group check happens before the thread terminates, and sometimes it happens after. If it happens after, we will have cleared the group.

it "returns the thread group explicitly set for this thread" do
  thread = Thread.new { nil }
  thread_group = ThreadGroup.new
  thread_group.add(thread)
  thread.group.should == thread_group
ensure
  thread.join if thread
end

@headius headius merged commit fe763ca into jruby:master Nov 14, 2024
@headius headius deleted the no_clear_threadgroup_in_thread_dispose branch November 14, 2024 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant