Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/puma/app/status.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json'

module Puma
module App
class Status
Expand Down Expand Up @@ -60,8 +62,7 @@ def call(env)
return rack_response(200, OK_STATUS)

when /\/gc-stats$/
json = "{" + GC.stat.map { |k, v| "\"#{k}\": #{v}" }.join(",") + "}"
return rack_response(200, json)
return rack_response(200, GC.stat.to_json)

when /\/stats$/
return rack_response(200, @cli.stats)
Expand Down
8 changes: 2 additions & 6 deletions test/test_cli.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require_relative "helper"

require "puma/cli"
require "json"

class TestCLI < Minitest::Test
def setup
Expand Down Expand Up @@ -195,12 +196,7 @@ def control_gc_stats(uri, cntl)

lines = body.split("\r\n")
json_line = lines.detect { |l| l[0] == "{" }
pairs = json_line.scan(/\"[^\"]+\": [^,]+/)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent JSON parsing - first gc-stats call not updated

Low Severity

The control_gc_stats method parses the /gc-stats JSON response twice: once for gc_count_before and once for gc_count_after. The PR only updated the second parsing to use JSON.parse (line 199), while the first parsing (lines 179-184) still uses the old regex-based approach. This creates an inconsistency within the same method - both instances parse the same JSON format but use different parsing methods.

Additional Locations (1)

Fix in Cursor Fix in Web

gc_stats = {}
pairs.each do |p|
p =~ /\"([^\"]+)\": ([^,]+)/ || raise("Can't parse #{p.inspect}!")
gc_stats[$1] = $2
end
gc_stats = JSON.parse(json_line)
gc_count_after = gc_stats["count"].to_i

# Hitting the /gc route should increment the count by 1
Expand Down