{"id":18489706,"url":"https://github.com/abicky/activerecord-debug_errors","last_synced_at":"2025-04-06T08:11:43.594Z","repository":{"id":44901758,"uuid":"307173610","full_name":"abicky/activerecord-debug_errors","owner":"abicky","description":"An extension of activerecord to display useful debug logs on errors","archived":false,"fork":false,"pushed_at":"2025-01-18T15:54:08.000Z","size":46,"stargazers_count":35,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T07:07:55.708Z","etag":null,"topics":["activerecord","rails"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/abicky.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-25T19:14:46.000Z","updated_at":"2025-03-07T00:11:27.000Z","dependencies_parsed_at":"2024-08-28T02:03:44.693Z","dependency_job_id":"556bac90-334f-45b6-98a6-c515c6b5dee5","html_url":"https://github.com/abicky/activerecord-debug_errors","commit_stats":{"total_commits":37,"total_committers":2,"mean_commits":18.5,"dds":0.3783783783783784,"last_synced_commit":"33d1264df979ed774dee3f8ff7d73abb27287dee"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abicky%2Factiverecord-debug_errors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abicky%2Factiverecord-debug_errors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abicky%2Factiverecord-debug_errors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abicky%2Factiverecord-debug_errors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abicky","download_url":"https://codeload.github.com/abicky/activerecord-debug_errors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247451653,"owners_count":20940939,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activerecord","rails"],"created_at":"2024-11-06T12:57:39.271Z","updated_at":"2025-04-06T08:11:43.576Z","avatar_url":"https://github.com/abicky.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ActiveRecord::DebugErrors\n\n[![CI](https://github.com/abicky/activerecord-debug_errors/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/abicky/activerecord-debug_errors/actions/workflows/test.yml)\n\nActiveRecord::DebugErrors is an extension of activerecord to display useful debug logs on errors.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'activerecord-debug_errors'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install activerecord-debug_errors\n\n## Usage\n\nYou only have to load the gem:\n\n```ruby\nrequire 'activerecord-debug_errors'\n```\n\nBy loading the gem, you can see useful debug logs on errors as described below.\n\n### ActiveRecord::LockWaitTimeout\n\nIf you use MySQL and when `ActiveRecord::LockWaitTimeout` occurs, you can see a log like below:\n\n```\nActiveRecord::LockWaitTimeout occurred:\n------------\nTRANSACTIONS\n------------\nTrx id counter 1511885\nPurge done for trx's n:o \u003c 1511588 undo n:o \u003c 0 state: running but idle\nHistory list length 42\nLIST OF TRANSACTIONS FOR EACH SESSION:\n---TRANSACTION 421781578720592, not started\n0 lock struct(s), heap size 1136, 0 row lock(s)\n---TRANSACTION 421781578719688, not started\n0 lock struct(s), heap size 1136, 0 row lock(s)\n---TRANSACTION 421781578718784, not started\n0 lock struct(s), heap size 1136, 0 row lock(s)\n---TRANSACTION 421781578716976, not started\n0 lock struct(s), heap size 1136, 0 row lock(s)\n---TRANSACTION 421781578717880, not started\n0 lock struct(s), heap size 1136, 0 row lock(s)\n---TRANSACTION 1511884, ACTIVE 2 sec\n1 lock struct(s), heap size 1136, 1 row lock(s)\nMySQL thread id 970, OS thread handle 123145454895104, query id 62140 localhost 127.0.0.1 root starting\nSHOW ENGINE INNODB STATUS\n---TRANSACTION 1511883, ACTIVE 2 sec\n3 lock struct(s), heap size 1136, 2 row lock(s)\nMySQL thread id 969, OS thread handle 123145455452160, query id 62138 localhost 127.0.0.1 root\n-----------\nPROCESSLIST\n-----------\n695     root    localhost:60956 information_schema      Sleep   3\n853     root    localhost:60036         Sleep   23\n966     root    localhost:54726 test    Sleep   2\n967     root    localhost:54731 test    Sleep   2\n968     root    localhost:54732 test    Sleep   2\n969     root    localhost:54734 test    Sleep   2\n970     root    localhost:54735 test    Query   0       starting        SHOW FULL PROCESSLIST\n```\n\nIn 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).\n\n\n### ActiveRecord::Deadlocked\n\nIf you use MySQL and when `ActiveRecord::Deadlocked` occurs, you can see the information of the latest detected deadlock:\n\n```\nActiveRecord::Deadlocked occurred:\n------------------------\nLATEST DETECTED DEADLOCK\n------------------------\n2020-10-26 05:16:54 0x700008fec000\n*** (1) TRANSACTION:\nTRANSACTION 1511857, ACTIVE 0 sec starting index read\nmysql tables in use 1, locked 1\nLOCK WAIT 4 lock struct(s), heap size 1136, 3 row lock(s)\nMySQL thread id 919, OS thread handle 123145453502464, query id 61760 localhost 127.0.0.1 root statistics\nSELECT `users`.* FROM `users` WHERE `users`.`name` = 'bar' LIMIT 1 FOR UPDATE\n*** (1) WAITING FOR THIS LOCK TO BE GRANTED:\nRECORD 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\nRecord lock, heap no 3 PHYSICAL RECORD: n_fields 2; compact format; info bits 0\n 0: len 3; hex 626172; asc bar;;\n 1: len 8; hex 8000000000000002; asc         ;;\n\n*** (2) TRANSACTION:\nTRANSACTION 1511858, ACTIVE 0 sec starting index read\nmysql tables in use 1, locked 1\n4 lock struct(s), heap size 1136, 3 row lock(s)\nMySQL thread id 920, OS thread handle 123145453223936, query id 61761 localhost 127.0.0.1 root statistics\nSELECT `users`.* FROM `users` WHERE `users`.`name` = 'foo' LIMIT 1 FOR UPDATE\n*** (2) HOLDS THE LOCK(S):\nRECORD 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\nRecord lock, heap no 3 PHYSICAL RECORD: n_fields 2; compact format; info bits 0\n 0: len 3; hex 626172; asc bar;;\n 1: len 8; hex 8000000000000002; asc         ;;\n\n*** (2) WAITING FOR THIS LOCK TO BE GRANTED:\nRECORD 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\nRecord lock, heap no 2 PHYSICAL RECORD: n_fields 2; compact format; info bits 0\n 0: len 3; hex 666f6f; asc foo;;\n 1: len 8; hex 8000000000000001; asc         ;;\n\n*** WE ROLL BACK TRANSACTION (2)\n```\n\nNote that the user requires the PROCESS priviledge to collect the information.\n\n### ActiveRecord::ConnectionTimeoutError\n\nWhen `ActiveRecord::ConnectionTimeoutError` occurs, you can see the information of connection owners (threads):\n\n```\nActiveRecord::ConnectionTimeoutError occurred:\n  connection owners:\n    Thread #\u003cThread:0x00007fbda205fa70 sleep_forever\u003e status=sleep priority=0\n        /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:32:in `join'\n        /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:32:in `each'\n        /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:32:in `block (4 levels) in \u003ctop (required)\u003e'\n        /path/to/ruby/gems/2.7.0/gems/rspec-expectations-3.9.3/lib/rspec/matchers/built_in/raise_error.rb:52:in `matches?'\n        /path/to/ruby/gems/2.7.0/gems/rspec-expectations-3.9.3/lib/rspec/expectations/handler.rb:50:in `block in handle_matcher'\n        /path/to/ruby/gems/2.7.0/gems/rspec-expectations-3.9.3/lib/rspec/expectations/handler.rb:27:in `with_matcher'\n        /path/to/ruby/gems/2.7.0/gems/rspec-expectations-3.9.3/lib/rspec/expectations/handler.rb:48:in `handle_matcher'\n        /path/to/ruby/gems/2.7.0/gems/rspec-expectations-3.9.3/lib/rspec/expectations/expectation_target.rb:65:in `to'\n        /path/to/ruby/gems/2.7.0/gems/rspec-expectations-3.9.3/lib/rspec/expectations/expectation_target.rb:101:in `to'\n        /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:26:in `block (3 levels) in \u003ctop (required)\u003e'\n-- snip --\n        /path/to/bin/rspec:23:in `load'\n        /path/to/bin/rspec:23:in `\u003cmain\u003e'\n    Thread #\u003cThread:0x00007fbda4908008 /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:29 dead\u003e status=false priority=0\n    Thread #\u003cThread:0x00007fbda4909688 /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:29 dead\u003e status=false priority=0\n    Thread #\u003cThread:0x00007fbda4908170 /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:29 dead\u003e status=false priority=0\n    Thread #\u003cThread:0x00007fbda48fbd58 /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:29 dead\u003e status=false priority=0\n  other threads:\n    Thread #\u003cThread: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\u003e status=sleep priority=0\n        /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'\n        /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'\n    Thread #\u003cThread:0x00007fbda5100170 /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:24 sleep\u003e status=sleep priority=0\n        /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:24:in `sleep'\n        /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:24:in `block (4 levels) in \u003ctop (required)\u003e'\n    Thread #\u003cThread:0x00007fbda48fbc40 /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:29 run\u003e status=run priority=0\n        /path/to/activerecord-debug_errors/lib/activerecord/debug_errors/ext/connection_adapters/connection_pool.rb:22:in `backtrace'\n        /path/to/activerecord-debug_errors/lib/activerecord/debug_errors/ext/connection_adapters/connection_pool.rb:22:in `block in dump_threads'\n        /path/to/activerecord-debug_errors/lib/activerecord/debug_errors/ext/connection_adapters/connection_pool.rb:34:in `each'\n        /path/to/activerecord-debug_errors/lib/activerecord/debug_errors/ext/connection_adapters/connection_pool.rb:34:in `dump_threads'\n        /path/to/activerecord-debug_errors/lib/activerecord/debug_errors/ext/connection_adapters/connection_pool.rb:9:in `rescue in acquire_connection'\n        /path/to/activerecord-debug_errors/lib/activerecord/debug_errors/ext/connection_adapters/connection_pool.rb:6:in `acquire_connection'\n        /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'\n        /path/to/activerecord-debug_errors/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb:30:in `block (6 levels) in \u003ctop (required)\u003e'\n```\n\nIn 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.\n\n## Development\n\nAfter 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.\n\nTo 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).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/abicky/activerecord-debug_errors.\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabicky%2Factiverecord-debug_errors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabicky%2Factiverecord-debug_errors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabicky%2Factiverecord-debug_errors/lists"}