mercredi 16 décembre 2015

Recently getting Rails-Mysql connection issues in production

Recently I have been getting strange errors in my production environment, running a rails 3.2.22 app with Mysql 5.6 using the mysql2 gem version 0.3.20

The errors appear seemingly random and if I try to reproduce the same situation, query, etc things go fine. Both in production and dev environments.

These are the errors I am getting:

A NoMethodError occurred in invoice_batches#show:

  undefined method `each' for nil:NilClass
  activerecord (3.2.22) lib/active_record/associations/preloader/association.rb:88:in `block in associated_records_by_owner'

.

A NoMethodError occurred in invoice_batches#show:

  undefined method `fields' for nil:NilClass
  activerecord (3.2.22) lib/active_record/connection_adapters/mysql2_adapter.rb:218:in `exec_query'

Stack inspection only shows internal Rails code, and none of my own code to debug.

Additionally, these native MySQL errors keep popping up

An ActiveRecord::StatementInvalid occurred in invoice_batches#show:

  Mysql2::Error: Lost connection to MySQL server during query: SELECT  `users`.* FROM `users`  WHERE `users`.`archived` = 0 AND `users`.`id` = 63 LIMIT 1
  activerecord (3.2.22) lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in `query'

and

An ActiveRecord::StatementInvalid occurred in templates#test_contract:

  Mysql2::Error: Malformed packet: SELECT `permissions`.`pkey` FROM `permissions`  WHERE `permissions`.`user_id` = 33 AND `permissions`.`client_id` = 7
  activerecord (3.2.22) lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in `query'

Which, again, I cannot seem to be able to reproduce or trace back to a cause in my code.

Any idea what this could be? I recently updated both the Mysql2 gem to the latest version (0.3.20) as well as the MySQL server from 5.5. to 5.6 Percona. These errors happened before and are still happening. Usually in close succession.

My database.yml has the following content for production:

production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: (...)
  pool: 5
  username: (...)
  password: (...)
  host: localhost
  flags: <%= 65536 | 131072 %>

Aucun commentaire:

Enregistrer un commentaire