Skip to content

Commit

Permalink
Mark the reporter thread as "fork safe" to avoid warnings
Browse files Browse the repository at this point in the history
This prevents the Reporter thread from generating warnings with puma,
which has been warning on any threads created before forking.

The Reporter thread is aware of forking by keeping the current `pid`
around, and initializing another thread if the `pid` changes. It means
we still have a running Reporter on the main puma process in this case,
plus one for each forked process (if running in cluster mode, in case of
puma.)

References:
rails/rails#40399
puma/puma#2475
https://github.com/puma/puma/releases/tag/v5.1.0

Closes #170
  • Loading branch information
carlosantoniodasilva committed Sep 9, 2024
1 parent a5f529f commit c1c2af2
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions judoscale-ruby/lib/judoscale/reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def start!(config, adapters)

def run_loop(config, metrics_collectors)
@_thread = Thread.new do
# Advise multi-threaded app servers to ignore this thread for the purposes of fork safety warnings.
Thread.current.thread_variable_set(:fork_safe, true)

loop do
run_metrics_collection(config, metrics_collectors)

Expand Down

0 comments on commit c1c2af2

Please sign in to comment.