debug_socket 0.1.8 → 0.1.9

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: 92e2954364c7dd4e35377fcf428a18359e1f0e08155976d3991d39b9c64445ae
4
- data.tar.gz: 5c970a58fca9e9c995b0223b988c48b2aea894906161bd336e566b4fbbdcab5f
3
+ metadata.gz: 8d2dbd80985d505fb3e16fe6c52dc1a52c7e597edca008a244edbd063246cf64
4
+ data.tar.gz: bf6e4ad9977359e46c8639a4791ef68f9b9a80b458183a23eb253bf5a9a375f1
5
5
  SHA512:
6
- metadata.gz: 603356c14c52452afcd8453a26dd657a0ef033b09f7b3df3ad0f50425ef9ea08d14998f430aceb1e85dc57d7819f7391acce142efc1466bbd4ede6ed758e1ac2
7
- data.tar.gz: 11ff34cbba7b9a01f7632fa59b5893427c8eeb2782387198946eb792724791c6c0cd7f9dded065c8934e8e3dc43b601d6cef6db081d2abf3b19113630ac05a1c
6
+ metadata.gz: 3041feb5fbad526e6eeb456adf2b769df4fde7dec715769e7cce7f2a20637652828613111c6f608edb6a03471bc6093e7a02c123f23dce9fdc9fe6149e4c0883
7
+ data.tar.gz: c4d468b0d3d142ab6b1be8d76dbb36ec2bace7b4d839ead868fb527b989bfe8b9cc549a740b3a407222044db71cba436aa24ca5e30b82fdbb4e40f466336c148
@@ -0,0 +1,34 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ "master" ]
13
+ pull_request:
14
+ branches: [ "master" ]
15
+
16
+ permissions:
17
+ contents: read
18
+
19
+ jobs:
20
+ test:
21
+ runs-on: ubuntu-latest
22
+ strategy:
23
+ matrix:
24
+ ruby-version: ['3.1', '3.2', '3.3', '3.4']
25
+
26
+ steps:
27
+ - uses: actions/checkout@v4
28
+ - name: Set up Ruby
29
+ uses: ruby/setup-ruby@v1
30
+ with:
31
+ ruby-version: ${{ matrix.ruby-version }}
32
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
33
+ - name: Run tests
34
+ run: bundle exec rake
data/.rubocop.yml CHANGED
@@ -1,15 +1,25 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.4
2
+ TargetRubyVersion: 3.1
3
3
  DisplayCopNames: true
4
+ NewCops: enable
4
5
 
5
- Style/FrozenStringLiteralComment:
6
- Enabled: true
6
+ plugins:
7
+ - rubocop-rake
8
+ - rubocop-rspec
7
9
 
10
+ Layout/LineLength:
11
+ Enabled: false
8
12
  Metrics:
9
13
  Enabled: false
10
-
14
+ RSpec/DescribedClass:
15
+ Enabled: false
16
+ RSpec/ExampleLength:
17
+ Enabled: false
18
+ RSpec/MultipleExpectations:
19
+ Enabled: false
11
20
  Style/Documentation:
12
21
  Enabled: false
13
-
22
+ Style/FrozenStringLiteralComment:
23
+ Enabled: true
14
24
  Style/StringLiterals:
15
25
  EnforcedStyle: double_quotes
data/CHANGES.md CHANGED
@@ -1,3 +1,15 @@
1
+ ### 0.1.9 2025-04-03
2
+
3
+ - [#17](https://github.com/square/debug_socket/pull/17)
4
+ Refactor error handling. Previously all errors (including `eval` errors) were caught in the same `rescue Exception`.
5
+ Now, we only `rescue Exception` for `eval` errors. For `DebugSocket` errors, we only `rescue StandardError` and we
6
+ allow 20 consecutive errors before `DebugSocket` gives up and dies permanently.
7
+ (@nerdrew)
8
+
9
+ - [#16](https://github.com/square/debug_socket/pull/16)
10
+ Allow external auditing of debug sessions.
11
+ (@doctown)
12
+
1
13
  ### 0.1.8 2022-10-10
2
14
 
3
15
  - [#15](https://github.com/square/debug_socket/pull/15)
data/Gemfile CHANGED
@@ -5,7 +5,13 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in debug_socket.gemspec
6
6
  gemspec
7
7
 
8
- gem "pry"
8
+ gem "base64"
9
+ gem "ostruct"
10
+ gem "pry-byebug"
9
11
  gem "rake"
10
12
  gem "rspec", "~> 3.8"
11
- gem "rubocop", "0.59.1"
13
+ gem "rubocop", "1.73.1"
14
+ gem "rubocop-rake"
15
+ gem "rubocop-rspec"
16
+ gem "ruby-lsp", require: false
17
+ gem "syntax_tree", require: false
data/debug_socket.gemspec CHANGED
@@ -17,4 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.bindir = "exe"
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
+ spec.metadata["rubygems_mfa_required"] = "true"
21
+
22
+ spec.required_ruby_version = ">= 3.1"
20
23
  end
data/exe/debug-socket CHANGED
@@ -12,8 +12,10 @@ end
12
12
  socket_path = ARGV[0]
13
13
  command = ARGV[1] || "backtrace"
14
14
 
15
- warn "\nSending `#{command}` to the following socket: #{socket_path}"\
15
+ warn(
16
+ "\nSending `#{command}` to the following socket: #{socket_path}" \
16
17
  "----------------------------------------------------------\n\n"
18
+ )
17
19
 
18
20
  UNIXSocket.open(socket_path) do |socket|
19
21
  socket.write(command)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DebugSocket
4
- VERSION = "0.1.8"
4
+ VERSION = "0.1.9"
5
5
  end
data/lib/debug_socket.rb CHANGED
@@ -5,6 +5,30 @@ require "socket"
5
5
  require "time"
6
6
 
7
7
  module DebugSocket
8
+ module Commands
9
+ # When running `eval`, we don't want the input to overwrite local variables etc. `eval` runs in the current scope,
10
+ # so we have an empty scope here that runs in a module that only has other shortcut commands the client might want
11
+ # to run.
12
+ def self.isolated_eval(input)
13
+ eval(input) # rubocop:disable Security/Eval
14
+ # We rescue Exception here because the input could have SyntaxErrors etc.
15
+ rescue Exception => e # rubocop:disable Lint/RescueException
16
+ DebugSocket.logger&.error { "debug-socket-error=#{e.inspect} input=#{input.inspect} path=#{@path} backtrace=#{e.backtrace.inspect}" }
17
+ "#{e.class.name}: #{e.message}\n#{e.backtrace.join("\n")}"
18
+ end
19
+
20
+ # Print the backtrace for every Thread
21
+ def self.backtrace
22
+ pid = Process.pid
23
+ "#{Time.now.utc.iso8601} #{$PROGRAM_NAME}\n" + Thread.list.map do |thread|
24
+ output = "#{Time.now.utc.iso8601} pid=#{pid} thread.object_id=#{thread.object_id} thread.status=#{thread.status}"
25
+ backtrace = thread.backtrace || []
26
+ output << "\n#{backtrace.join("\n")}" if backtrace
27
+ output
28
+ end.join("\n\n")
29
+ end
30
+ end
31
+
8
32
  @thread = nil
9
33
  @pid = Process.pid
10
34
 
@@ -16,10 +40,10 @@ module DebugSocket
16
40
  return @logger if defined?(@logger)
17
41
 
18
42
  require "logger"
19
- @logger = Logger.new(STDERR)
43
+ @logger = Logger.new($stderr)
20
44
  end
21
45
 
22
- def self.start(path)
46
+ def self.start(path, &block)
23
47
  pid = Process.pid
24
48
  raise "debug socket thread already running for this process" if @thread && @pid == pid
25
49
 
@@ -32,18 +56,27 @@ module DebugSocket
32
56
 
33
57
  server = UNIXServer.new(@path)
34
58
  @thread = Thread.new do
59
+ errors = 0
35
60
  loop do
36
- begin
37
- socket = server.accept
38
- input = socket.read
39
- logger&.warn("debug-socket-command=#{input.inspect}")
40
- socket.puts(eval(input)) # rubocop:disable Security/Eval
41
- rescue Exception => e # rubocop:disable Lint/RescueException
42
- logger&.error { "debug-socket-error=#{e.inspect} backtrace=#{e.backtrace.inspect}" }
43
- ensure
44
- socket&.close
45
- end
61
+ socket = server.accept
62
+ input = socket.read
63
+ logger&.warn("debug-socket-command=#{input.inspect}")
64
+
65
+ perform_audit(input, &block) if block
66
+ socket.puts(Commands.isolated_eval(input))
67
+
68
+ errors = 0
69
+ rescue StandardError => e
70
+ errors += 1
71
+ logger&.error { "debug-socket-error=#{e.inspect} errors=#{errors} path=#{@path} backtrace=#{e.backtrace.inspect}" }
72
+ raise e if errors > 20
73
+
74
+ sleep(1)
75
+ ensure
76
+ socket&.close
46
77
  end
78
+ rescue Exception => e # rubocop:disable Lint/RescueException
79
+ logger&.error { "debug-socket-error=#{e.inspect} DebugSocket is broken now path=#{@path} backtrace=#{e.backtrace.inspect}" }
47
80
  end
48
81
 
49
82
  logger&.unknown { "Debug socket listening on #{@path}" }
@@ -61,14 +94,10 @@ module DebugSocket
61
94
  @path = nil
62
95
  end
63
96
 
64
- def self.backtrace
65
- pid = Process.pid
66
- "#{Time.now.utc.iso8601} #{$PROGRAM_NAME}\n" + Thread.list.map do |thread|
67
- output =
68
- +"#{Time.now.utc.iso8601} pid=#{pid} thread.object_id=#{thread.object_id} thread.status=#{thread.status}"
69
- backtrace = thread.backtrace || []
70
- output << "\n#{backtrace.join("\n")}" if backtrace
71
- output
72
- end.join("\n\n")
97
+ # Allow debug socket input commands to be audited by an external callback
98
+ private_class_method def self.perform_audit(input)
99
+ yield input
100
+ rescue Exception => e # rubocop:disable Lint/RescueException
101
+ logger&.error "debug-socket-error=callback unsuccessful: #{e.inspect} for #{input.inspect} path=#{@path} backtrace=#{e.backtrace.inspect}"
73
102
  end
74
103
  end
metadata CHANGED
@@ -1,16 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debug_socket
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Lazarus
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2022-10-17 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
- description:
14
12
  email:
15
13
  - lazarus@squareup.com
16
14
  executables:
@@ -18,10 +16,10 @@ executables:
18
16
  extensions: []
19
17
  extra_rdoc_files: []
20
18
  files:
19
+ - ".github/workflows/ruby.yml"
21
20
  - ".gitignore"
22
21
  - ".rspec"
23
22
  - ".rubocop.yml"
24
- - ".travis.yml"
25
23
  - CHANGES.md
26
24
  - Gemfile
27
25
  - LICENSE.txt
@@ -35,8 +33,8 @@ files:
35
33
  - lib/debug_socket/version.rb
36
34
  homepage: https://github.com/square/debug_socket
37
35
  licenses: []
38
- metadata: {}
39
- post_install_message:
36
+ metadata:
37
+ rubygems_mfa_required: 'true'
40
38
  rdoc_options: []
41
39
  require_paths:
42
40
  - lib
@@ -44,15 +42,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
44
42
  requirements:
45
43
  - - ">="
46
44
  - !ruby/object:Gem::Version
47
- version: '0'
45
+ version: '3.1'
48
46
  required_rubygems_version: !ruby/object:Gem::Requirement
49
47
  requirements:
50
48
  - - ">="
51
49
  - !ruby/object:Gem::Version
52
50
  version: '0'
53
51
  requirements: []
54
- rubygems_version: 3.3.3
55
- signing_key:
52
+ rubygems_version: 3.6.7
56
53
  specification_version: 4
57
54
  summary: Debug Socket for running ruby processes
58
55
  test_files: []
data/.travis.yml DELETED
@@ -1,11 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.3.4
4
- - 2.4.1
5
- - jruby-9.1.13.0
6
- - ruby-head
7
- matrix:
8
- allow_failures:
9
- - rvm: ruby-head
10
- fast_finish: true
11
- sudo: false