ruby-concurrency / concurrent-ruby

Modern concurrency tools including agents, futures, promises, thread pools, supervisors, and more. Inspired by Erlang, Clojure, Scala, Go, Java, JavaScript, and classic concurrency patterns.
https://ruby-concurrency.github.io/concurrent-ruby/
Other
5.68k stars 418 forks source link

DaemonThreadFactory creating new Java thread factory each time it creates a new thread #1008

Open obulkin opened 1 year ago

obulkin commented 1 year ago

Background Info

Issue

Concurrent::DaemonThreadFactory#newThread calls defaultThreadFactory() each time it generates a new thread, which creates a new Java ThreadFactory object each time. This is clearly at odds with intended ThreadFactory usage and is (potentially) problematic in a few ways:

Proposed Solution

Call defaultThreadFactory() once in Concurrent::DaemonThreadFactory#initialize, store the resulting factory in an instance variable, and reuse it as needed in Concurrent::DaemonThreadFactory#newThread.

Happy to create a PR with the fix if this seems like an acceptable solution.

eregon commented 1 year ago

Thanks for the report. Yes, that makes sense, a PR would be helpful.

obulkin commented 1 year ago

Excellent. I'll get started on one.

obulkin commented 1 year ago

@eregon PR is up now: https://github.com/ruby-concurrency/concurrent-ruby/pull/1009

The CI failure seems like a flaky test since the test case doesn't seem related to my changes and passed under JRuby.

obulkin commented 1 year ago

@eregon Checking in on this. I recommitted my changes to force a new test run, and everything is green this time.

obulkin commented 1 year ago

Checking in. Please let me know if I can do anything to move this along. The PR is very minimal and should be quick to review.

obulkin commented 11 months ago

@eregon Bumping again

eregon commented 11 months ago

Merged. Do you need a release?

obulkin commented 11 months ago

Thanks! No urgent need for a release if there's something else in the pipeline that you'd prefer to bundle it with.