rails-profiler 0.44.3 → 0.44.4

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: ce11aa11e9b78a74592597cff00560918498f66c5305d9fc6b56c5a31016da4a
4
- data.tar.gz: fe2cb8e6c676ea9d8ee578b50619191e6bc6615c5c61276b6b9a244f01d89da5
3
+ metadata.gz: 83d59af955c9b38a889d0d2e8e1de82c0e1b7cd6e281a74545fdc078eba838ef
4
+ data.tar.gz: ac543e209b57284122855d727d2b0dfd1ce36948462642fae681e040e432507e
5
5
  SHA512:
6
- metadata.gz: a34e01876ec49e00c57c9e2825826d5a3c8b932bf949e6c3096a763c342a9248fb6697ccc38b29027cff641554f2259b5ae5c2278d4aff50eba03a067003bb07
7
- data.tar.gz: f1ff8d35947b09461d0a304b5caea8f60ec3d19da5714e98574446cd29cce72764860f522da487e59ab941cf6bc95da62ab0ea0d754693cb76a4105dd49688b2
6
+ metadata.gz: f81c36af2b33e98e1dcf90c855f5929e41f149236265ce65aeb24794cd536a8f4b41218d768aed511aee3fac6ed5f56a28ef044597c8f3cd779bf25675964a51
7
+ data.tar.gz: e0a804252b573fd3b934fb77bb14c20367042fe61cde6e1e4340401726f4e09442c72b27ccd7029fa6bbd3e09b3d4bca9b9c4123c12d42a7d9d57e1dedd8db23
data/CHANGELOG.md CHANGED
@@ -19,6 +19,14 @@ every commit of every tag interval is accounted for one way or the other.
19
19
 
20
20
  ## [Unreleased]
21
21
 
22
+ ## [0.44.4] - 2026-10-21
23
+
24
+ <!-- stamped -->
25
+
26
+ ### Fixed
27
+
28
+ - **Cluster:** a slave no longer delays the boot of the server, of `rails console` or of a rake task when its master is unreachable. The first registration now runs in the heartbeat thread instead of `after_initialize`, and calls to the master time out after 3 seconds to connect and 5 seconds to read, instead of 60 seconds each.
29
+
22
30
  ## [0.44.3] - 2026-10-21
23
31
 
24
32
  <!-- stamped -->
@@ -20,6 +20,10 @@ module Profiler
20
20
  end
21
21
  end
22
22
 
23
+ # A master that does not answer must cost the heartbeat thread a few seconds, not a minute.
24
+ OPEN_TIMEOUT = 3
25
+ READ_TIMEOUT = 5
26
+
23
27
  class << self
24
28
  # The client the railtie started in this process, for the fork hook to restart.
25
29
  attr_accessor :current
@@ -42,12 +46,7 @@ module Profiler
42
46
  self.class.current = self
43
47
  self.class.install_fork_hook!
44
48
  @registered = false
45
- begin
46
- register!
47
- @registered = true
48
- rescue => e
49
- log_warn("could not register with master at startup, will retry in the heartbeat loop", e)
50
- end
49
+ @failed = false
51
50
  @started = true
52
51
  start_heartbeat_thread
53
52
  end
@@ -59,6 +58,7 @@ module Profiler
59
58
  return if @started.nil? || @thread&.alive?
60
59
 
61
60
  @registered = false
61
+ @failed = false
62
62
  start_heartbeat_thread
63
63
  end
64
64
 
@@ -68,7 +68,7 @@ module Profiler
68
68
  config = Profiler.configuration
69
69
  uri = master_uri("register")
70
70
  body = { name: config.resolved_name, url: config.self_url }.to_json
71
- resp = Profiler.untracked_http { Net::HTTP.post(uri, body, request_headers) }
71
+ resp = post(uri, body)
72
72
  unless resp.code.to_i.between?(200, 299)
73
73
  raise "Master returned #{resp.code}: #{resp.body.to_s.slice(0, 200)}"
74
74
  end
@@ -80,10 +80,19 @@ module Profiler
80
80
  config = Profiler.configuration
81
81
  uri = master_uri("heartbeat")
82
82
  body = { name: config.resolved_name }.to_json
83
- resp = Profiler.untracked_http { Net::HTTP.post(uri, body, request_headers) }
83
+ resp = post(uri, body)
84
84
  raise "Heartbeat rejected #{resp.code}" unless resp.code.to_i.between?(200, 299)
85
85
  end
86
86
 
87
+ def post(uri, body)
88
+ Profiler.untracked_http do
89
+ Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https",
90
+ open_timeout: OPEN_TIMEOUT, read_timeout: READ_TIMEOUT) do |http|
91
+ http.post(uri.request_uri, body, request_headers)
92
+ end
93
+ end
94
+ end
95
+
87
96
  # Refused before any request when the secret would cross the network in clear, or when
88
97
  # there is no secret for the master to accept.
89
98
  def master_uri(action)
@@ -111,20 +120,24 @@ module Profiler
111
120
  @thread = Profiler::Instrumentation::RequestContext.detached { Thread.new { heartbeat_loop } }
112
121
  end
113
122
 
123
+ # The first registration is the first turn of the loop, so an unreachable master never
124
+ # delays the boot of the process that started the client.
114
125
  def heartbeat_loop
115
126
  interval = Profiler.configuration.cluster_heartbeat_interval
116
127
  loop do
117
- sleep interval
118
- unless @registered
128
+ if @registered
129
+ heartbeat!
130
+ else
119
131
  register!
120
132
  @registered = true
121
- log_info("Re-registered with master after previous failure")
122
- else
123
- heartbeat!
133
+ log_info("Re-registered with master after previous failure") if @failed
124
134
  end
125
135
  rescue => e
126
136
  @registered = false
137
+ @failed = true
127
138
  log_warn("communication with the master failed, will retry", e)
139
+ ensure
140
+ sleep interval
128
141
  end
129
142
  end
130
143
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Profiler
4
- VERSION = "0.44.3"
4
+ VERSION = "0.44.4"
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.3
4
+ version: 0.44.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sébastien Duplessy