Open herbertia opened 5 years ago
Since you have this failure during unit tests, can you try isolating the test(s) that cause the crash?
I am going to try to isolate the tests but as it is random I'll see if I can reproduce it on a project
Any luck isolating this issue in your test suite?
Yes I got the root cause of the problem. The mysql2 gem is crashing when doing the tests and in your model you have in a callback a job launched. Even if you don't test the job as the after callbacks are now fired in test it makes the gem to crash. I don't know if there is a solution to have an error message instead of a crash...
Can you post a minimal reproduction case?
Yes I am going to try to do it this week.
I'm seeing the same issue - the empty Mysql2::Error in 'affected_rows').
It also happens in a delete_all
statement.
It's in an integration test though. So it may be a bit harder to isolate. I thought it was related to rails threat handling because it started showing up after i started using transactional fixtures in capybara integration tests again. This is with mariadb 10.1.38 runnig in docker. Rails 5.2.3, mysql2 0.5.2
I do not see any errors in the mysql error log or mysql general log.
I have not been able to reproduce this in a unit test. @herbertia , is this happening in a unit or an integration test for you?
I have some similar issues but only on MySQL server version 8.0.17 (Community Server - GPL):
size:
[1m[35m (0.5ms)[0m [1m[34mSELECT COUNT(*) FROM `exports` WHERE `exports`.`date` = '2020-02-11'[0m
↳ config/initializers/scheduler.rb:21
--------------------------------------------------------------------------------
Mysql2::Error::ConnectionError: Wrong or unknown protocol: SELECT COUNT(*) FROM `exports` WHERE `exports`.`date` = '2020-02-11'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mysql2-0.5.3-x64-mingw32/lib/mysql2/client.rb:131:in `_query'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mysql2-0.5.3-x64-mingw32/lib/mysql2/client.rb:131:in `block in query'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mysql2-0.5.3-x64-mingw32/lib/mysql2/client.rb:130:in `handle_interrupt'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mysql2-0.5.3-x64-mingw32/lib/mysql2/client.rb:130:in `query'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:187:in `block (2 levels) in execute'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activesupport-5.2.4.1/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activesupport-5.2.4.1/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activesupport-5.2.4.1/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:186:in `block in execute'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract_adapter.rb:581:in `block (2 levels) in log'
D:/RubyonRails/Ruby24-x64/lib/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract_adapter.rb:580:in `block in log'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activesupport-5.2.4.1/lib/active_support/notifications/instrumenter.rb:23:in `instrument'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract_adapter.rb:571:in `log'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:185:in `execute'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/mysql/database_statements.rb:28:in `execute'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:196:in `execute_and_free'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/mysql/database_statements.rb:33:in `exec_query'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/database_statements.rb:478:in `select'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/database_statements.rb:70:in `select_all'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/query_cache.rb:106:in `select_all'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/mysql/database_statements.rb:12:in `select_all'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activerecord-5.2.4.1/lib/active_record/relation/calculations.rb:286:in `block in execute_simple_calculation'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activerecord-5.2.4.1/lib/active_record/relation.rb:584:in `skip_query_cache_if_necessary'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activerecord-5.2.4.1/lib/active_record/relation/calculations.rb:286:in `execute_simple_calculation'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activerecord-5.2.4.1/lib/active_record/relation/calculations.rb:238:in `perform_calculation'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activerecord-5.2.4.1/lib/active_record/relation/calculations.rb:146:in `calculate'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activerecord-5.2.4.1/lib/active_record/relation/calculations.rb:52:in `count'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activerecord-5.2.4.1/lib/active_record/relation.rb:211:in `size'
D:/RubyonRails/Projekt/config/initializers/scheduler.rb:21:in `block in <top (required)>'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rufus-scheduler-3.6.0/lib/rufus/scheduler/jobs.rb:223:in `do_call'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rufus-scheduler-3.6.0/lib/rufus/scheduler/jobs.rb:267:in `trigger_now'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rufus-scheduler-3.6.0/lib/rufus/scheduler/jobs.rb:312:in `block (3 levels) in start_work_thread'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rufus-scheduler-3.6.0/lib/rufus/scheduler/jobs.rb:315:in `block (2 levels) in start_work_thread'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rufus-scheduler-3.6.0/lib/rufus/scheduler/jobs.rb:301:in `loop'
D:/RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rufus-scheduler-3.6.0/lib/rufus/scheduler/jobs.rb:301:in `block in start_work_thread'
--------------------------------------------------------------------------------
in a task that is doing the same things again and againg every 10 minutes. When I start my application it works but only in the first run. In the second run it crashes. On another server with MySQL 8.0.16 (Community Server - GPL) the same DB and code it works well. Any idea why?
EDIT: I updatet both to 8.0.19 and have the same behaviour. On one machine it works like intended - on the other it runs 1 time and crashes in the second.
I am in the process to upgrade our application to Rails 5. I have upgraded to ruby 2.4.5 with all the gems in our gemfile with Rails 5.2.2. The mysql2 gem is 0.5.2. When I am running our tests and I have randoms errors:
Mysql2::Error
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activerecord-5.2.2/lib/active_record/connection_adapters/mysql/database_statements.rb:45:in 'affected_rows'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activerecord-5.2.2/lib/active_record/connection_adapters/mysql/database_statements.rb:45:in 'block in exec_delete'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:196:in 'execute_and_free'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activerecord-5.2.2/lib/active_record/connection_adapters/mysql/database_statements.rb:45:in 'exec_delete'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:168:in 'delete'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/query_cache.rb:21:in 'delete'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activerecord-5.2.2/lib/active_record/relation.rb:409:in 'delete_all'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activerecord-5.2.2/lib/active_record/querying.rb:10:in 'delete_all'
or this kind of mysql errors:
Failure/Error: _query(sql, @query_options.merge(options))
ActiveRecord::StatementInvalid:
Mysql2::Error::ConnectionError: MySQL server has gone away: BEGIN
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/mysql2-0.5.2/lib/mysql2/client.rb:131:in '_query'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/mysql2-0.5.2/lib/mysql2/client.rb:131:in 'block in query'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/mysql2-0.5.2/lib/mysql2/client.rb:130:in 'handle_interrupt'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/mysql2-0.5.2/lib/mysql2/client.rb:130:in 'query'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:187:in 'block (2 levels) in execute'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activesupport-5.2.2/lib/active_support/dependencies/interlock.rb:48:in 'block in permit_concurrent_loads'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activesupport-5.2.2/lib/active_support/concurrency/share_lock.rb:187:in 'yield_shares'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activesupport-5.2.2/lib/active_support/dependencies/interlock.rb:47:in 'permit_concurrent_loads'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:186:in 'block in execute'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:579:in 'block (2 levels) in log'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:578:in 'block in log'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activesupport-5.2.2/lib/active_support/notifications/instrumenter.rb:23:in 'instrument'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:569:in 'log'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:185:in 'execute'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activerecord-5.2.2/lib/active_record/connection_adapters/mysql/database_statements.rb:28:in 'execute'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:200:in 'begin_db_transaction'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/transaction.rb:175:in 'initialize'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/transaction.rb:201:in 'new'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/transaction.rb:201:in 'block in begin_transaction'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/transaction.rb:197:in 'begin_transaction'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:267:in 'begin_transaction'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activerecord-5.2.2/lib/active_record/fixtures.rb:975:in 'block in setup_fixtures'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activerecord-5.2.2/lib/active_record/fixtures.rb:974:in 'each'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activerecord-5.2.2/lib/active_record/fixtures.rb:974:in 'setup_fixtures'
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/activerecord-5.2.2/lib/active_record/fixtures.rb:860:in 'before_setup'
# ------------------
# --- Caused by: ---
# Mysql2::Error::ConnectionError:
# MySQL server has gone away
# /usr/local/rvm/gems/ruby-2.4.5@clm/gems/mysql2-0.5.2/lib/mysql2/client.rb:131:in '_query'
Then I have some malloc crashes:
ruby(73560,0x70000d9c0000) malloc: *** error for object 0x7f9bdb234000: pointer being freed was not allocated
ruby(73560,0x70000d9c0000) malloc: *** set a breakpoint in malloc_error_break to debug
The sometimes I have SEGFault:
/usr/local/rvm/gems/ruby-2.4.5@clm/gems/mysql2-0.5.2/lib/mysql2/client.rb:131: [BUG] Segmentation fault at 0xffffffffffffffe1 ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-darwin18]
Each time I am running the same tests I have either a crash or a seg fault and the mysql errors. It never happens at the same place or in the same tests. The same tests are running perfectly on Ruby 2.2.9, Rails 4.2.8 with mysql2 0.4.10. It has been several days that I am trying to google the issue without success. The versions are not that recent and I don't see reported issues.
I tried to uninstall mysql2, then re-install it. I have mysql 5.7 installed on my mac. I am on Mac OS 10.14.2.
Please advise