rails-profiler 0.44.20 → 0.44.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12ce9dde45b6c00f05d7496da2b765adbb843bc7e35cd956f9294a88bc06f34d
4
- data.tar.gz: 6a114fab97682f2375bb1d778016d1279ba5f00cbcc5a43ca61767b9fedcb220
3
+ metadata.gz: 4e8274bd0fb2cb58fdfd37a2e93aecd9097b76700926326862373201a5ffb806
4
+ data.tar.gz: 6e639fb12156b9ae0729a64ffbb62f40611484b8e7258503f1e44a9021a7472d
5
5
  SHA512:
6
- metadata.gz: 60573fb7ef5502e652815f5101cb111775e4bd16a9a2cd9f18f90f19542c95080548b24a84a130cce667510d421ae1d68fcf2aa4ec4d6bca3733330587d62781
7
- data.tar.gz: a7af8dd153a21e6a47d86f7eceb3085313bfe2953d68b76a817c21a9d57f87e352c017b47454beb5045a706e36b7fb25e4fb509a326e8740f41dac995528b201
6
+ metadata.gz: 80093b790074db0100eff63bb0b795d010dd40dc885c1ed44b3d7009b6717223faf648e5ef3903181897dbc4a15b958ff11777381faf26e601bb748d54923ebe
7
+ data.tar.gz: 8b219ed177c7427e2d0c4750652c1403f49e37205779ac486aa3c931d3e952f3501003bd0578c1c49f4111573b9491a023418776327847c7664578376677b72e
data/CHANGELOG.md CHANGED
@@ -19,6 +19,18 @@ every commit of every tag interval is accounted for one way or the other.
19
19
 
20
20
  ## [Unreleased]
21
21
 
22
+ ## [0.44.21] - 2026-10-25
23
+
24
+ <!-- stamped -->
25
+
26
+ ### Fixed
27
+
28
+ - **HTTP and Flame Graph collectors:** threads spawned during a profiled request but surviving
29
+ afterwards (a `Timeout.timeout` watcher, a Honeybadger or Bugsnag worker,
30
+ a `Concurrent::ScheduledTask`) no longer indefinitely pollute the profile with unbounded
31
+ entries and repeated re-saves. Collectors now refuse new entries after a grace period
32
+ (0.5 seconds) or when entry count exceeds 100, whichever comes first.
33
+
22
34
  ## [0.44.20] - 2026-10-25
23
35
 
24
36
  <!-- stamped -->
@@ -11,6 +11,7 @@ module Profiler
11
11
  @events = []
12
12
  @subscriptions = []
13
13
  @mutex = Mutex.new
14
+ @released_at = nil
14
15
  end
15
16
 
16
17
  def icon
@@ -152,6 +153,7 @@ module Profiler
152
153
  def unsubscribe
153
154
  unsubscribe_notifications(@subscriptions)
154
155
  restore_thread_slots
156
+ @released_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
155
157
  end
156
158
 
157
159
  def toolbar_summary
@@ -163,6 +165,13 @@ module Profiler
163
165
 
164
166
  private
165
167
 
168
+ def add_event_allowed?
169
+ return true unless @released_at
170
+
171
+ grace_period = 0.5
172
+ (Process.clock_gettime(Process::CLOCK_MONOTONIC) - @released_at) <= grace_period && @events.size < 100
173
+ end
174
+
166
175
  def build_hierarchy(events)
167
176
  return [] if events.empty?
168
177
 
@@ -193,7 +202,9 @@ module Profiler
193
202
  end
194
203
 
195
204
  def add_event(event)
196
- @mutex.synchronize { @events << event }
205
+ @mutex.synchronize do
206
+ @events << event if add_event_allowed?
207
+ end
197
208
  end
198
209
 
199
210
  def short_identifier(identifier)
@@ -11,6 +11,7 @@ module Profiler
11
11
  @requests = []
12
12
  @mutex = Mutex.new
13
13
  @collected = false
14
+ @released_at = nil
14
15
  end
15
16
 
16
17
  def icon
@@ -48,6 +49,7 @@ module Profiler
48
49
  # records nothing when no collector holds the thread-local slot.
49
50
  def unsubscribe
50
51
  restore_thread_slots
52
+ @released_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
51
53
  end
52
54
 
53
55
  def collect
@@ -62,11 +64,23 @@ module Profiler
62
64
 
63
65
  # Called from NetHttpInstrumentation before the actual HTTP call.
64
66
  # Returns the mutable entry so the caller can update it on completion.
67
+ # Returns nil if the collector has been released and the grace period or entry cap is exceeded,
68
+ # to prevent fire-and-forget threads from indefinitely polluting the profile after the request ends.
65
69
  def register_pending(payload)
66
70
  entry = payload.merge(in_flight: true, status: 0, duration: nil,
67
71
  response_headers: {}, response_body: nil,
68
72
  response_body_encoding: "text", response_size: 0)
69
- @mutex.synchronize { @requests << entry }
73
+
74
+ @mutex.synchronize do
75
+ # Refuse new entries if released and (grace period expired OR cap exceeded). Checked
76
+ # and appended under the same lock, so concurrent fire-and-forget threads cannot all
77
+ # pass the cap together.
78
+ if @released_at
79
+ grace_period = 0.5
80
+ return nil if (Process.clock_gettime(Process::CLOCK_MONOTONIC) - @released_at) > grace_period || @requests.size >= 100
81
+ end
82
+ @requests << entry
83
+ end
70
84
  save_if_collected
71
85
  entry
72
86
  end
@@ -65,39 +65,42 @@ module Profiler
65
65
 
66
66
  response = super
67
67
 
68
- duration = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - t0) * 1000).round(2)
69
- # read_body with a block hands each chunk to the block and keeps none: the response then
70
- # holds a Net::ReadAdapter, whose to_s is an inspect and whose bytes are gone.
71
- streamed = NetHttpInstrumentation.streamed_body?(response)
72
- resp_body_raw = streamed ? "" : response.body.to_s
73
- resp_content_encoding = response["content-encoding"].to_s.strip.downcase
74
- resp_body = NetHttpInstrumentation.decompress_body(resp_body_raw, resp_content_encoding, limit)
75
- resp_truncated = limit ? resp_body.bytesize > limit : false
76
- resp_body = Redaction.cut_bytes(resp_body, limit) if resp_truncated
77
- resp_content_type = response["content-type"].to_s
78
- processed_resp = NetHttpInstrumentation.process_body(resp_body, resp_content_type)
79
-
80
- t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
81
-
82
- collector.complete_request(
83
- entry,
84
- status: response.code.to_i,
85
- duration: duration,
86
- response_headers: Redaction.filter_headers(response.to_hash.transform_values { |v| v.join(", ") }),
87
- response_body: processed_resp[:body],
88
- response_body_encoding: processed_resp[:encoding],
89
- response_size: streamed ? (declared_length(response) || 0) : resp_body_raw.bytesize,
90
- response_body_truncated: resp_truncated,
91
- response_body_not_captured: streamed
92
- )
93
-
94
- fg = Thread.current[:profiler_flamegraph_collector]
95
- fg&.record_http_event(started_at: t0, finished_at: t1, url: url, method: req.method, status: response.code.to_i)
68
+ # Only record response details if the collector accepted the request
69
+ if entry
70
+ duration = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - t0) * 1000).round(2)
71
+ # read_body with a block hands each chunk to the block and keeps none: the response then
72
+ # holds a Net::ReadAdapter, whose to_s is an inspect and whose bytes are gone.
73
+ streamed = NetHttpInstrumentation.streamed_body?(response)
74
+ resp_body_raw = streamed ? "" : response.body.to_s
75
+ resp_content_encoding = response["content-encoding"].to_s.strip.downcase
76
+ resp_body = NetHttpInstrumentation.decompress_body(resp_body_raw, resp_content_encoding, limit)
77
+ resp_truncated = limit ? resp_body.bytesize > limit : false
78
+ resp_body = Redaction.cut_bytes(resp_body, limit) if resp_truncated
79
+ resp_content_type = response["content-type"].to_s
80
+ processed_resp = NetHttpInstrumentation.process_body(resp_body, resp_content_type)
81
+
82
+ t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
83
+
84
+ collector.complete_request(
85
+ entry,
86
+ status: response.code.to_i,
87
+ duration: duration,
88
+ response_headers: Redaction.filter_headers(response.to_hash.transform_values { |v| v.join(", ") }),
89
+ response_body: processed_resp[:body],
90
+ response_body_encoding: processed_resp[:encoding],
91
+ response_size: streamed ? (declared_length(response) || 0) : resp_body_raw.bytesize,
92
+ response_body_truncated: resp_truncated,
93
+ response_body_not_captured: streamed
94
+ )
95
+
96
+ fg = Thread.current[:profiler_flamegraph_collector]
97
+ fg&.record_http_event(started_at: t0, finished_at: t1, url: url, method: req.method, status: response.code.to_i)
98
+ end
96
99
 
97
100
  response
98
101
  rescue => e
99
102
  duration = defined?(t0) && t0 ? ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - t0) * 1000).round(2) : 0.0
100
- if defined?(entry) && entry
103
+ if defined?(entry) && entry && defined?(collector) && collector
101
104
  collector.fail_request(entry, error: e.message, duration: duration)
102
105
  end
103
106
  raise
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Profiler
4
- VERSION = "0.44.20"
4
+ VERSION = "0.44.21"
5
5
 
6
6
  GEM_ROOT = File.expand_path("../..", __dir__)
7
7
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.44.20
4
+ version: 0.44.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sébastien Duplessy