activerecord-debug_errors 0.1.0
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 +7 -0
- data/.github/workflows/test.yml +52 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +172 -0
- data/Rakefile +6 -0
- data/activerecord-debug_errors.gemspec +27 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/activerecord-debug_errors.rb +1 -0
- data/lib/activerecord/debug_errors.rb +9 -0
- data/lib/activerecord/debug_errors/ext/connection_adapters/abstract_mysql_adapter.rb +70 -0
- data/lib/activerecord/debug_errors/ext/connection_adapters/connection_pool.rb +34 -0
- data/lib/activerecord/debug_errors/version.rb +5 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 05b9bd693072c5abead086c372a274d69bc524422a70c1e4e160115ba7f0d242
|
4
|
+
data.tar.gz: d32300ef7d84b3623de67b8009ab947023db5e1c0c3ee65728a47f4f7dee1b32
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9ac1f359d84dd981f6564cf628bb1529da8155c194a153d966cc5e3a94bbd0840327ecabe0dd77ad303d9102197afdaa8f51c172899c3cc29f5b3dafbacf30f6
|
7
|
+
data.tar.gz: 367f5b98b80af8d240cff69d5f9f8c8bcd0dd8a71ab2cdfb486df0b71403f6d777d063d5b937ffc6def902c1829f85f564572ae5bb30056b0584d76ec173e265
|
@@ -0,0 +1,52 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
pull_request:
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
build:
|
9
|
+
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
timeout-minutes: 10
|
12
|
+
strategy:
|
13
|
+
fail-fast: false
|
14
|
+
matrix:
|
15
|
+
ruby-version:
|
16
|
+
- '2.6'
|
17
|
+
- '2.7'
|
18
|
+
services:
|
19
|
+
mysql:
|
20
|
+
image: mysql:5.7
|
21
|
+
ports:
|
22
|
+
- 3306:3306
|
23
|
+
options: >-
|
24
|
+
--health-cmd "mysqladmin ping -h localhost"
|
25
|
+
--health-interval 10s
|
26
|
+
--health-timeout 5s
|
27
|
+
--health-retries 5
|
28
|
+
env:
|
29
|
+
MYSQL_ROOT_PASSWORD: password
|
30
|
+
MYSQL_DATABASE: test
|
31
|
+
steps:
|
32
|
+
- uses: actions/checkout@v2
|
33
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
34
|
+
uses: actions/setup-ruby@v1
|
35
|
+
with:
|
36
|
+
ruby-version: ${{ matrix.ruby-version }}
|
37
|
+
- uses: actions/cache@v2
|
38
|
+
with:
|
39
|
+
path: vendor/bundle
|
40
|
+
key: ${{ runner.os }}-gems-${{ matrix.ruby-version }}-${{ hashFiles('activerecord-debug_errors.gemspec', '**/Gemfile') }}
|
41
|
+
restore-keys: |
|
42
|
+
${{ runner.os }}-gems-${{ matrix.ruby-version }}-
|
43
|
+
- name: Build and test with Rake
|
44
|
+
run: |
|
45
|
+
bundle config path vendor/bundle
|
46
|
+
bundle install --jobs 4 --retry 3
|
47
|
+
bundle exec rake
|
48
|
+
env:
|
49
|
+
MYSQL_HOST: 127.0.0.1
|
50
|
+
MYSQL_USERNAME: root
|
51
|
+
MYSQL_PASSWORD: password
|
52
|
+
MYSQL_DATABASE: test
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 abicky
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
# ActiveRecord::DebugErrors
|
2
|
+
|
3
|
+

|
4
|
+
|
5
|
+
ActiveRecord::DebugErrors is an extension of activerecord to display useful debug logs on errors.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'activerecord-debug_errors'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install activerecord-debug_errors
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
You only have to load the gem:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'activerecord-debug_errors'
|
29
|
+
```
|
30
|
+
|
31
|
+
By loading the gem, you can see useful debug logs on errors as described below.
|
32
|
+
|
33
|
+
### ActiveRecord::LockWaitTimeout
|
34
|
+
|
35
|
+
When `ActiveRecord::LockWaitTimeout` occurs, you can see a log like below:
|
36
|
+
|
37
|
+
```
|
38
|
+
ActiveRecord::LockWaitTimeout occurred:
|
39
|
+
------------
|
40
|
+
TRANSACTIONS
|
41
|
+
------------
|
42
|
+
Trx id counter 1511885
|
43
|
+
Purge done for trx's n:o < 1511588 undo n:o < 0 state: running but idle
|
44
|
+
History list length 42
|
45
|
+
LIST OF TRANSACTIONS FOR EACH SESSION:
|
46
|
+
---TRANSACTION 421781578720592, not started
|
47
|
+
0 lock struct(s), heap size 1136, 0 row lock(s)
|
48
|
+
---TRANSACTION 421781578719688, not started
|
49
|
+
0 lock struct(s), heap size 1136, 0 row lock(s)
|
50
|
+
---TRANSACTION 421781578718784, not started
|
51
|
+
0 lock struct(s), heap size 1136, 0 row lock(s)
|
52
|
+
---TRANSACTION 421781578716976, not started
|
53
|
+
0 lock struct(s), heap size 1136, 0 row lock(s)
|
54
|
+
---TRANSACTION 421781578717880, not started
|
55
|
+
0 lock struct(s), heap size 1136, 0 row lock(s)
|
56
|
+
---TRANSACTION 1511884, ACTIVE 2 sec
|
57
|
+
1 lock struct(s), heap size 1136, 1 row lock(s)
|
58
|
+
MySQL thread id 970, OS thread handle 123145454895104, query id 62140 localhost 127.0.0.1 root starting
|
59
|
+
SHOW ENGINE INNODB STATUS
|
60
|
+
---TRANSACTION 1511883, ACTIVE 2 sec
|
61
|
+
3 lock struct(s), heap size 1136, 2 row lock(s)
|
62
|
+
MySQL thread id 969, OS thread handle 123145455452160, query id 62138 localhost 127.0.0.1 root
|
63
|
+
-----------
|
64
|
+
PROCESSLIST
|
65
|
+
-----------
|
66
|
+
695 root localhost:60956 information_schema Sleep 3
|
67
|
+
853 root localhost:60036 Sleep 23
|
68
|
+
966 root localhost:54726 test Sleep 2
|
69
|
+
967 root localhost:54731 test Sleep 2
|
70
|
+
968 root localhost:54732 test Sleep 2
|
71
|
+
969 root localhost:54734 test Sleep 2
|
72
|
+
970 root localhost:54735 test Query 0 starting SHOW FULL PROCESSLIST
|
73
|
+
```
|
74
|
+
|
75
|
+
In the preceding log, you can find that there were two long transactions. The first one was created by thread id 969 (the client localhost:54734), and the second one was created by thread id 970 (the client localhost:54735).
|
76
|
+
|
77
|
+
|
78
|
+
### ActiveRecord::Deadlocked
|
79
|
+
|
80
|
+
When `ActiveRecord::Deadlocked` occurs, you can see the information of the latest detected deadlock:
|
81
|
+
|
82
|
+
```
|
83
|
+
ActiveRecord::Deadlocked occurred:
|
84
|
+
------------------------
|
85
|
+
LATEST DETECTED DEADLOCK
|
86
|
+
------------------------
|
87
|
+
2020-10-26 05:16:54 0x700008fec000
|
88
|
+
*** (1) TRANSACTION:
|
89
|
+
TRANSACTION 1511857, ACTIVE 0 sec starting index read
|
90
|
+
mysql tables in use 1, locked 1
|
91
|
+
LOCK WAIT 4 lock struct(s), heap size 1136, 3 row lock(s)
|
92
|
+
MySQL thread id 919, OS thread handle 123145453502464, query id 61760 localhost 127.0.0.1 root statistics
|
93
|
+
SELECT `users`.* FROM `users` WHERE `users`.`name` = 'bar' LIMIT 1 FOR UPDATE
|
94
|
+
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
|
95
|
+
RECORD LOCKS space id 6659 page no 4 n bits 72 index ux_name of table `test`.`users` trx id 1511857 lock_mode X locks rec but not gap waiting
|
96
|
+
Record lock, heap no 3 PHYSICAL RECORD: n_fields 2; compact format; info bits 0
|
97
|
+
0: len 3; hex 626172; asc bar;;
|
98
|
+
1: len 8; hex 8000000000000002; asc ;;
|
99
|
+
|
100
|
+
*** (2) TRANSACTION:
|
101
|
+
TRANSACTION 1511858, ACTIVE 0 sec starting index read
|
102
|
+
mysql tables in use 1, locked 1
|
103
|
+
4 lock struct(s), heap size 1136, 3 row lock(s)
|
104
|
+
MySQL thread id 920, OS thread handle 123145453223936, query id 61761 localhost 127.0.0.1 root statistics
|
105
|
+
SELECT `users`.* FROM `users` WHERE `users`.`name` = 'foo' LIMIT 1 FOR UPDATE
|
106
|
+
*** (2) HOLDS THE LOCK(S):
|
107
|
+
RECORD LOCKS space id 6659 page no 4 n bits 72 index ux_name of table `test`.`users` trx id 1511858 lock_mode X locks rec but not gap
|
108
|
+
Record lock, heap no 3 PHYSICAL RECORD: n_fields 2; compact format; info bits 0
|
109
|
+
0: len 3; hex 626172; asc bar;;
|
110
|
+
1: len 8; hex 8000000000000002; asc ;;
|
111
|
+
|
112
|
+
*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
|
113
|
+
RECORD LOCKS space id 6659 page no 4 n bits 72 index ux_name of table `test`.`users` trx id 1511858 lock_mode X locks rec but not gap waiting
|
114
|
+
Record lock, heap no 2 PHYSICAL RECORD: n_fields 2; compact format; info bits 0
|
115
|
+
0: len 3; hex 666f6f; asc foo;;
|
116
|
+
1: len 8; hex 8000000000000001; asc ;;
|
117
|
+
|
118
|
+
*** WE ROLL BACK TRANSACTION (2)
|
119
|
+
```
|
120
|
+
|
121
|
+
### ActiveRecord::ConnectionTimeoutError
|
122
|
+
|
123
|
+
When `ActiveRecord::ConnectionTimeoutError` occurs, you can see the information of connection owners (threads):
|
124
|
+
|
125
|
+
```
|
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'
|
149
|
+
-- 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
|
156
|
+
```
|
157
|
+
|
158
|
+
|
159
|
+
## Development
|
160
|
+
|
161
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
162
|
+
|
163
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
164
|
+
|
165
|
+
## Contributing
|
166
|
+
|
167
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/abicky/activerecord-debug_errors.
|
168
|
+
|
169
|
+
|
170
|
+
## License
|
171
|
+
|
172
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'lib/activerecord/debug_errors/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "activerecord-debug_errors"
|
5
|
+
spec.version = ActiveRecord::DebugErrors::VERSION
|
6
|
+
spec.authors = ["abicky"]
|
7
|
+
spec.email = ["takeshi.arabiki@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{An extension of activerecord to display useful debug logs on errors}
|
10
|
+
spec.description = %q{ActiveRecord::DebugErrors is an extension of activerecord to display useful debug logs on errors.}
|
11
|
+
spec.homepage = "https://github.com/abicky/activerecord-debug_errors"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
17
|
+
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_runtime_dependency "activerecord", ">= 6", "< 7"
|
26
|
+
spec.add_development_dependency "mysql2"
|
27
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "activerecord/debug_errors"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "activerecord/debug_errors"
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require "active_record"
|
2
|
+
require "activerecord/debug_errors/ext/connection_adapters/abstract_mysql_adapter"
|
3
|
+
require "activerecord/debug_errors/ext/connection_adapters/connection_pool"
|
4
|
+
require "activerecord/debug_errors/version"
|
5
|
+
|
6
|
+
module ActiveRecord
|
7
|
+
module DebugErrors
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module DebugErrors
|
5
|
+
module DisplayMySQLInformation
|
6
|
+
def execute(*args)
|
7
|
+
super
|
8
|
+
rescue ActiveRecord::Deadlocked
|
9
|
+
if logger
|
10
|
+
logger.error "ActiveRecord::Deadlocked occurred:"
|
11
|
+
display_latest_detected_deadlock
|
12
|
+
end
|
13
|
+
raise
|
14
|
+
rescue ActiveRecord::LockWaitTimeout
|
15
|
+
if logger
|
16
|
+
logger.error "ActiveRecord::LockWaitTimeout occurred:"
|
17
|
+
display_transactions
|
18
|
+
display_processlist
|
19
|
+
end
|
20
|
+
raise
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def display_latest_detected_deadlock
|
26
|
+
display_innodb_status_section("LATEST DETECTED DEADLOCK")
|
27
|
+
end
|
28
|
+
|
29
|
+
def display_transactions
|
30
|
+
display_innodb_status_section("TRANSACTIONS")
|
31
|
+
end
|
32
|
+
|
33
|
+
def display_processlist
|
34
|
+
logger.error "-----------"
|
35
|
+
logger.error "PROCESSLIST"
|
36
|
+
logger.error "-----------"
|
37
|
+
ActiveRecord::Base.connection.execute("SHOW FULL PROCESSLIST").each do |row|
|
38
|
+
logger.error row.join("\t")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def display_innodb_status_section(section_name)
|
43
|
+
status = ActiveRecord::Base.connection.execute("SHOW ENGINE INNODB STATUS").first[2]
|
44
|
+
|
45
|
+
prev_line = nil
|
46
|
+
in_deadlock_section = false
|
47
|
+
status.each_line do |line|
|
48
|
+
line.chomp!
|
49
|
+
|
50
|
+
if line == section_name
|
51
|
+
logger.error prev_line
|
52
|
+
in_deadlock_section = true
|
53
|
+
end
|
54
|
+
|
55
|
+
if in_deadlock_section
|
56
|
+
break if prev_line != section_name && line.match?(/\A-+\z/)
|
57
|
+
logger.error line
|
58
|
+
end
|
59
|
+
|
60
|
+
prev_line = line
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
require "active_record/connection_adapters/abstract_mysql_adapter"
|
68
|
+
class ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter
|
69
|
+
prepend ActiveRecord::DebugErrors::DisplayMySQLInformation
|
70
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module DebugErrors
|
5
|
+
module DisplayConnectionOwners
|
6
|
+
def acquire_connection(*args)
|
7
|
+
super
|
8
|
+
rescue ActiveRecord::ConnectionTimeoutError
|
9
|
+
display_connection_owners if ActiveRecord::Base.logger
|
10
|
+
raise
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def display_connection_owners
|
16
|
+
logger = ActiveRecord::Base.logger
|
17
|
+
|
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}"
|
21
|
+
thread.backtrace&.each do |bt|
|
22
|
+
logger.error " #{bt}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
require "active_record/connection_adapters/abstract/connection_pool"
|
32
|
+
class ActiveRecord::ConnectionAdapters::ConnectionPool
|
33
|
+
prepend ActiveRecord::DebugErrors::DisplayConnectionOwners
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activerecord-debug_errors
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- abicky
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-10-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '6'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '7'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '6'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '7'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: mysql2
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
description: ActiveRecord::DebugErrors is an extension of activerecord to display
|
48
|
+
useful debug logs on errors.
|
49
|
+
email:
|
50
|
+
- takeshi.arabiki@gmail.com
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- ".github/workflows/test.yml"
|
56
|
+
- ".gitignore"
|
57
|
+
- ".rspec"
|
58
|
+
- Gemfile
|
59
|
+
- LICENSE.txt
|
60
|
+
- README.md
|
61
|
+
- Rakefile
|
62
|
+
- activerecord-debug_errors.gemspec
|
63
|
+
- bin/console
|
64
|
+
- bin/setup
|
65
|
+
- lib/activerecord-debug_errors.rb
|
66
|
+
- lib/activerecord/debug_errors.rb
|
67
|
+
- lib/activerecord/debug_errors/ext/connection_adapters/abstract_mysql_adapter.rb
|
68
|
+
- lib/activerecord/debug_errors/ext/connection_adapters/connection_pool.rb
|
69
|
+
- lib/activerecord/debug_errors/version.rb
|
70
|
+
homepage: https://github.com/abicky/activerecord-debug_errors
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata:
|
74
|
+
homepage_uri: https://github.com/abicky/activerecord-debug_errors
|
75
|
+
source_code_uri: https://github.com/abicky/activerecord-debug_errors
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 2.6.0
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubygems_version: 3.1.4
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: An extension of activerecord to display useful debug logs on errors
|
95
|
+
test_files: []
|