From fe31aadd5b33f7c5670493a8a5c8d7a96bb69a52 Mon Sep 17 00:00:00 2001 From: MSP-Greg Date: Sun, 17 May 2020 11:46:14 -0500 Subject: [PATCH] Load JSON at runtime Closes #2206 --- History.md | 1 + lib/puma.rb | 1 + lib/puma/app/status.rb | 6 ++++-- lib/puma/cluster.rb | 3 ++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/History.md b/History.md index e34abaa3a1..a6d4745468 100644 --- a/History.md +++ b/History.md @@ -26,6 +26,7 @@ * Configuration: `environment` is read from `RAILS_ENV`, if `RACK_ENV` can't be found (#2022) * Bugfixes + * Fix JSON loading issues on phased-restarts (#2269) * Close client http connections made to an ssl server with TLSv1.3 (#2116) * Do not set user_config to quiet by default to allow for file config (#2074) * Always close SSL connection in Puma::ControlCLI (#2211) diff --git a/lib/puma.rb b/lib/puma.rb index bd667116f1..86f5d97a27 100644 --- a/lib/puma.rb +++ b/lib/puma.rb @@ -20,6 +20,7 @@ def self.stats_object=(val) end def self.stats + require 'json' @get_stats.stats.to_json end diff --git a/lib/puma/app/status.rb b/lib/puma/app/status.rb index efffc43cff..0fdef3824a 100644 --- a/lib/puma/app/status.rb +++ b/lib/puma/app/status.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'json' - module Puma module App # Check out {#call}'s source code to see what actions this web application @@ -19,6 +17,10 @@ def call(env) return rack_response(403, 'Invalid auth token', 'text/plain') end + if env['PATH_INFO'] =~ /\/(gc-stats|stats|thread-backtraces)$/ + require 'json' + end + case env['PATH_INFO'] when /\/stop$/ @cli.stop diff --git a/lib/puma/cluster.rb b/lib/puma/cluster.rb index 861b231a13..aff32ab885 100644 --- a/lib/puma/cluster.rb +++ b/lib/puma/cluster.rb @@ -5,7 +5,6 @@ require 'puma/plugin' require 'time' -require 'json' module Puma # This class is instantiated by the `Puma::Launcher` and used @@ -95,6 +94,7 @@ def term? def ping!(status) @last_checkin = Time.now + require 'json' @last_status = JSON.parse(status, symbolize_names: true) end @@ -330,6 +330,7 @@ def worker(index, master) while true sleep Const::WORKER_CHECK_INTERVAL begin + require 'json' io << "p#{Process.pid}#{server.stats.to_json}\n" rescue IOError Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue