activerecord-debug_errors 0.1.0 → 0.1.1

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: 05b9bd693072c5abead086c372a274d69bc524422a70c1e4e160115ba7f0d242
4
- data.tar.gz: d32300ef7d84b3623de67b8009ab947023db5e1c0c3ee65728a47f4f7dee1b32
3
+ metadata.gz: 818e63536312d27e39718e58eb6ec33827cd703e245f284c806e53d4dfcc86dc
4
+ data.tar.gz: b177c2624722f1a5bd01f5378c252c6344d134679704f2e816ccbf2b184732f7
5
5
  SHA512:
6
- metadata.gz: 9ac1f359d84dd981f6564cf628bb1529da8155c194a153d966cc5e3a94bbd0840327ecabe0dd77ad303d9102197afdaa8f51c172899c3cc29f5b3dafbacf30f6
7
- data.tar.gz: 367f5b98b80af8d240cff69d5f9f8c8bcd0dd8a71ab2cdfb486df0b71403f6d777d063d5b937ffc6def902c1829f85f564572ae5bb30056b0584d76ec173e265
6
+ metadata.gz: 2198d3f0a7a61a1d71f1c171c8fa9aaa1a4a7f650ae40fb69c39bf95f37ed83aa3d0c125b2beaa2032cac1a7ec05938607448b3266a399e79bd774476dd69610
7
+ data.tar.gz: d6a9a8df96bff2a512468e3c56ce07099a2eee6818a9adef13422d832bb1b22cb2dadc0450b960f0ed244d6d21223453e3fd957fac67816fc4c0ba1770de0943
data/README.md CHANGED
@@ -32,7 +32,7 @@ By loading the gem, you can see useful debug logs on errors as described below.
32
32
 
33
33
  ### ActiveRecord::LockWaitTimeout
34
34
 
35
- When `ActiveRecord::LockWaitTimeout` occurs, you can see a log like below:
35
+ If you use MySQL and when `ActiveRecord::LockWaitTimeout` occurs, you can see a log like below:
36
36
 
37
37
  ```
38
38
  ActiveRecord::LockWaitTimeout occurred:
@@ -77,7 +77,7 @@ In the preceding log, you can find that there were two long transactions. The fi
77
77
 
78
78
  ### ActiveRecord::Deadlocked
79
79
 
80
- When `ActiveRecord::Deadlocked` occurs, you can see the information of the latest detected deadlock:
80
+ If you use MySQL and when `ActiveRecord::Deadlocked` occurs, you can see the information of the latest detected deadlock:
81
81
 
82
82
  ```
83
83
  ActiveRecord::Deadlocked occurred:
@@ -124,37 +124,44 @@ When `ActiveRecord::ConnectionTimeoutError` occurs, you can see the information
124
124
 
125
125
  ```
126
126
  ActiveRecord::ConnectionTimeoutError occured:
127
- Thread #<Thread:0x00007fce2105fa90 sleep_forever> status=sleep priority=0
128
- /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:25:in `join'
129
- /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:25:in `each'
130
- /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:25:in `block (4 levels) in <top (required)>'
131
- /path/to/ruby/gems/2.7.0/gems/rspec-expectations-3.9.3/lib/rspec/matchers/built_in/raise_error.rb:52:in `matches?'
132
- /path/to/ruby/gems/2.7.0/gems/rspec-expectations-3.9.3/lib/rspec/expectations/handler.rb:50:in `block in handle_matcher'
133
- /path/to/ruby/gems/2.7.0/gems/rspec-expectations-3.9.3/lib/rspec/expectations/handler.rb:27:in `with_matcher'
134
- /path/to/ruby/gems/2.7.0/gems/rspec-expectations-3.9.3/lib/rspec/expectations/handler.rb:48:in `handle_matcher'
135
- /path/to/ruby/gems/2.7.0/gems/rspec-expectations-3.9.3/lib/rspec/expectations/expectation_target.rb:65:in `to'
136
- /path/to/ruby/gems/2.7.0/gems/rspec-expectations-3.9.3/lib/rspec/expectations/expectation_target.rb:101:in `to'
137
- /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:20:in `block (3 levels) in <top (required)>'
138
- /path/to/ruby/gems/2.7.0/gems/rspec-core-3.9.3/lib/rspec/core/example.rb:262:in `instance_exec'
139
- /path/to/ruby/gems/2.7.0/gems/rspec-core-3.9.3/lib/rspec/core/example.rb:262:in `block in run'
140
- /path/to/ruby/gems/2.7.0/gems/rspec-core-3.9.3/lib/rspec/core/example.rb:508:in `block in with_around_and_singleton_context_hooks'
141
- /path/to/ruby/gems/2.7.0/gems/rspec-core-3.9.3/lib/rspec/core/example.rb:465:in `block in with_around_example_hooks'
142
- /path/to/ruby/gems/2.7.0/gems/rspec-core-3.9.3/lib/rspec/core/hooks.rb:486:in `block in run'
143
- /path/to/ruby/gems/2.7.0/gems/rspec-core-3.9.3/lib/rspec/core/hooks.rb:626:in `block in run_around_example_hooks_for'
144
- /path/to/ruby/gems/2.7.0/gems/rspec-core-3.9.3/lib/rspec/core/example.rb:350:in `call'
145
- /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:13:in `block (2 levels) in <top (required)>'
146
- /path/to/ruby/gems/2.7.0/gems/rspec-core-3.9.3/lib/rspec/core/example.rb:455:in `instance_exec'
147
- /path/to/ruby/gems/2.7.0/gems/rspec-core-3.9.3/lib/rspec/core/example.rb:455:in `instance_exec'
148
- /path/to/ruby/gems/2.7.0/gems/rspec-core-3.9.3/lib/rspec/core/hooks.rb:390:in `execute_with'
127
+ connection owners:
128
+ Thread #<Thread:0x00007fbda205fa70 sleep_forever> status=sleep priority=0
129
+ /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:32:in `join'
130
+ /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:32:in `each'
131
+ /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:32:in `block (4 levels) in <top (required)>'
132
+ /path/to/ruby/gems/2.7.0/gems/rspec-expectations-3.9.3/lib/rspec/matchers/built_in/raise_error.rb:52:in `matches?'
133
+ /path/to/ruby/gems/2.7.0/gems/rspec-expectations-3.9.3/lib/rspec/expectations/handler.rb:50:in `block in handle_matcher'
134
+ /path/to/ruby/gems/2.7.0/gems/rspec-expectations-3.9.3/lib/rspec/expectations/handler.rb:27:in `with_matcher'
135
+ /path/to/ruby/gems/2.7.0/gems/rspec-expectations-3.9.3/lib/rspec/expectations/handler.rb:48:in `handle_matcher'
136
+ /path/to/ruby/gems/2.7.0/gems/rspec-expectations-3.9.3/lib/rspec/expectations/expectation_target.rb:65:in `to'
137
+ /path/to/ruby/gems/2.7.0/gems/rspec-expectations-3.9.3/lib/rspec/expectations/expectation_target.rb:101:in `to'
138
+ /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:26:in `block (3 levels) in <top (required)>'
149
139
  -- snip --
150
- /path/to/ruby/gems/2.7.0/gems/rspec-core-3.9.3/lib/rspec/core/runner.rb:45:in `invoke'
151
- /path/to/ruby/gems/2.7.0/gems/rspec-core-3.9.3/exe/rspec:4:in `<main>'
152
- Thread #<Thread:0x00007fce23b80cb0 /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:22 dead> status=false priority=0
153
- Thread #<Thread:0x00007fce23b809e0 /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:22 dead> status=false priority=0
154
- Thread #<Thread:0x00007fce23b806e8 /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:22 dead> status=false priority=0
155
- Thread #<Thread:0x00007fce23b804b8 /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:22 dead> status=false priority=0
140
+ /path/to/bin/rspec:23:in `load'
141
+ /path/to/bin/rspec:23:in `<main>'
142
+ Thread #<Thread:0x00007fbda4908008 /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:29 dead> status=false priority=0
143
+ Thread #<Thread:0x00007fbda4909688 /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:29 dead> status=false priority=0
144
+ Thread #<Thread:0x00007fbda4908170 /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:29 dead> status=false priority=0
145
+ Thread #<Thread:0x00007fbda48fbd58 /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:29 dead> status=false priority=0
146
+ other threads:
147
+ Thread #<Thread:0x00007fbda52b3ad0 /path/to/ruby/gems/2.7.0/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:334 sleep> status=sleep priority=0
148
+ /path/to/ruby/gems/2.7.0/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:337:in `sleep'
149
+ /path/to/ruby/gems/2.7.0/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:337:in `block in spawn_thread'
150
+ Thread #<Thread:0x00007fbda5100170 /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:24 sleep> status=sleep priority=0
151
+ /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:24:in `sleep'
152
+ /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:24:in `block (4 levels) in <top (required)>'
153
+ Thread #<Thread:0x00007fbda48fbc40 /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:29 run> status=run priority=0
154
+ /path/to/activerecord-debug_errors/lib/activerecord/debug_errors/ext/connection_adapters/connection_pool.rb:22:in `backtrace'
155
+ /path/to/activerecord-debug_errors/lib/activerecord/debug_errors/ext/connection_adapters/connection_pool.rb:22:in `block in dump_threads'
156
+ /path/to/activerecord-debug_errors/lib/activerecord/debug_errors/ext/connection_adapters/connection_pool.rb:34:in `each'
157
+ /path/to/activerecord-debug_errors/lib/activerecord/debug_errors/ext/connection_adapters/connection_pool.rb:34:in `dump_threads'
158
+ /path/to/activerecord-debug_errors/lib/activerecord/debug_errors/ext/connection_adapters/connection_pool.rb:9:in `rescue in acquire_connection'
159
+ /path/to/activerecord-debug_errors/lib/activerecord/debug_errors/ext/connection_adapters/connection_pool.rb:6:in `acquire_connection'
160
+ /path/to/ruby/gems/2.7.0/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:593:in `checkout'
161
+ /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:30:in `block (6 levels) in <top (required)>'
156
162
  ```
157
163
 
164
+ In the preceding log, you can find that there were five connection owners and three other threads. The first owner was the main thread (Thread:0x00007fbda205fa70) and the other owners are dead threads.
158
165
 
159
166
  ## Development
160
167
 
@@ -6,21 +6,32 @@ module ActiveRecord
6
6
  def acquire_connection(*args)
7
7
  super
8
8
  rescue ActiveRecord::ConnectionTimeoutError
9
- display_connection_owners if ActiveRecord::Base.logger
9
+ dump_threads if ActiveRecord::Base.logger
10
10
  raise
11
11
  end
12
12
 
13
13
  private
14
14
 
15
- def display_connection_owners
15
+ def dump_threads
16
16
  logger = ActiveRecord::Base.logger
17
17
 
18
18
  logger.error "ActiveRecord::ConnectionTimeoutError occured:"
19
- ActiveRecord::Base.connection_pool.connections.map(&:owner).each do |thread|
20
- logger.error " Thread #{thread} status=#{thread.status} priority=#{thread.priority}"
19
+
20
+ dump_thread = ->(thread) {
21
+ logger.error " Thread #{thread} status=#{thread.status} priority=#{thread.priority}"
21
22
  thread.backtrace&.each do |bt|
22
- logger.error " #{bt}"
23
+ logger.error " #{bt}"
23
24
  end
25
+ }
26
+
27
+ owners = ActiveRecord::Base.connection_pool.connections.map(&:owner)
28
+ logger.error " connection owners:"
29
+ owners.each(&dump_thread)
30
+
31
+ other_threads = Thread.list - owners
32
+ unless other_threads.empty?
33
+ logger.error " other threads:"
34
+ other_threads.each(&dump_thread)
24
35
  end
25
36
  end
26
37
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module DebugErrors
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-debug_errors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - abicky
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-25 00:00:00.000000000 Z
11
+ date: 2020-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord