ruby-concurrency / ruby-concurrency/concurrent-ruby

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

Offen
#1,008 8 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Ruby
Sterne
5.8k
Forks
420
Ø Merge
20 Std. 45 Min.
Gemergte PRs (30 T.)
4

Beschreibung

Background Info
  • Ruby implementation: JRuby
  • concurrent-ruby version: >= 1.1.10, earlier versions may be affected as well
  • concurrent-ruby-ext installed: no
  • concurrent-ruby-edge used: no
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:

  • It leads to thread names of the form pool-X-thread-Y, where Y is always 1 while X is different for each thread. This is confusing as it suggests that the Concurrent Ruby thread pool is not actually pooling and reusing threads.
  • This does not seem to be happening in the Concurrent Ruby code, but if a reference to each ThreadFactory instance is retained somewhere, the result will be a memory leak.
  • Threads created by a ThreadFactory instance normally belong to the same Java thread group, which has permissions implications and may cause errors in code that expects all the threads in a Concurrent Ruby thread pool to belong to the same Java thread group.
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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Search for Concurrent::DaemonThreadFactory and read its initialize and newThread methods, along with the use of defaultThreadFactory(). Reuse one Java ThreadFactory for the instance as proposed, then verify that threads created by the factory use incrementing thread numbers and share the intended thread factory and group.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
java, ruby
Bereich
backend
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.