app_profiler 0.1.4 → 0.1.5

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: eaffd76839111b3280bce8241889441b85b4346121e1478cc60839f791916445
4
- data.tar.gz: f9aab66b3b52953756610b9acb8a314178ce535075d8702d4ced0624e4880409
3
+ metadata.gz: 11304574ae151e5775c7cbac93ace38b9784c25bec088b39b4288eae719a0d1e
4
+ data.tar.gz: d0a698c95c617c4a337c9e31953b374f5f3a9d6126df942674928491c81e97c5
5
5
  SHA512:
6
- metadata.gz: c299676be9b01c62ab73885f1e6b8c6b787721acbe94266b71fec79d91e623bd599aee7b6607eb17dda0f0187a1024c43227c9bae256b660cd8155f41a9dacf4
7
- data.tar.gz: f1fd90215f29e46175ca3cd3f7bbaeed4448a40acf07e25aa1a1f7c59d8b10cc66854e0c6453cdc4367a469b03e16c8b930da6d53034e0e1d92e1b9dd4b5b5d4
6
+ metadata.gz: b511cd5273c64b1f58597e6a12e668b78e2d5037e63626e4cb34927b3814fb0fb7962fee01973a6be71d928f04596a71525fac3c62bbaadabea6b49121dbae5c
7
+ data.tar.gz: 507918c0fcb2d4e2321b5401bdd243a3a74fdc256576bdd4be0eddf7441a73bbed4738a9a880d6e507918db0d2a6d9c05bc10adb67a3b6741b7e22fdf16e67e2
@@ -198,11 +198,26 @@ module AppProfiler
198
198
  end
199
199
 
200
200
  class UNIX < Transport
201
+ class << self
202
+ def unlink_socket(path, pid)
203
+ ->(_) do
204
+ if Process.pid == pid && File.exist?(path)
205
+ begin
206
+ File.unlink(path)
207
+ rescue SystemCallError
208
+ # Let not raise in a finalizer
209
+ end
210
+ end
211
+ end
212
+ end
213
+ end
214
+
201
215
  def start
202
216
  FileUtils.mkdir_p(PROFILER_TEMPFILE_PATH)
203
217
  @socket_file = File.join(PROFILER_TEMPFILE_PATH, "app-profiler-#{Process.pid}.sock")
204
218
  File.unlink(@socket_file) if File.exist?(@socket_file) && File.socket?(@socket_file)
205
219
  @socket = UNIXServer.new(@socket_file)
220
+ ObjectSpace.define_finalizer(self, self.class.unlink_socket(@socket_file, Process.pid))
206
221
  end
207
222
 
208
223
  def client
@@ -213,6 +228,10 @@ module AppProfiler
213
228
  File.unlink(@socket_file) if File.exist?(@socket_file) && File.socket?(@socket_file)
214
229
  @socket.close
215
230
  end
231
+
232
+ def abandon
233
+ @socket.close
234
+ end
216
235
  end
217
236
 
218
237
  class TCP < Transport
@@ -238,6 +257,11 @@ module AppProfiler
238
257
  @port_file.unlink
239
258
  @socket.close
240
259
  end
260
+
261
+ def abandon
262
+ @port_file.close # NB: Tempfile finalizer checks Process.pid to avoid unlinking inherited IOs.
263
+ @socket.close
264
+ end
241
265
  end
242
266
 
243
267
  def initialize(transport, logger)
@@ -257,13 +281,16 @@ module AppProfiler
257
281
  "[AppProfiler::Server] listening on addr=#{@transport.socket.addr}"
258
282
  )
259
283
  @pid = Process.pid
260
- at_exit { stop }
261
284
  end
262
285
 
263
286
  def client
264
287
  @transport.client
265
288
  end
266
289
 
290
+ def join(...)
291
+ @listen_thread.join(...)
292
+ end
293
+
267
294
  def serve
268
295
  return unless @listen_thread.nil?
269
296
 
@@ -324,10 +351,12 @@ module AppProfiler
324
351
  end
325
352
 
326
353
  def stop
327
- return unless @pid == Process.pid
328
-
329
354
  @listen_thread.kill
330
- @transport.stop
355
+ if @pid == Process.pid
356
+ @transport.stop
357
+ else
358
+ @transport.abandon
359
+ end
331
360
  end
332
361
  end
333
362
 
@@ -371,7 +400,10 @@ module AppProfiler
371
400
  private
372
401
 
373
402
  def profile_server
374
- @profile_server = nil if @pid != Process.pid
403
+ if @pid != Process.pid
404
+ @profile_server&.stop
405
+ @profile_server = nil
406
+ end
375
407
  @profile_server
376
408
  end
377
409
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AppProfiler
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: app_profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gannon McGibbon
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2023-09-20 00:00:00.000000000 Z
16
+ date: 2023-09-25 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: activesupport