Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Random MySQL exceptions in my Rails application

I'm having issues with my MySQL backend for my Rails app.

Basically every time I deploy, I start getting weird exceptions like

ActiveRecord::StatementInvalid: Mysql2::Error: 
NoMethodError: undefined method `fields' for nil:NilClass
ActiveModel::MissingAttributeError: missing attribute: created_at
ActiveRecord::StatementInvalid: Mysql2::Error: Lost connection to MySQL server during query
ActiveRecord::UnknownPrimaryKey: Unknown primary key for table users in model User.
RuntimeError: Session collision on '"017fab6b21d2ef20d30e6119f7bf...."'

I'm not sure if this is happening because of sudden load, which my MySQL instance isn't able to take, but it happens 99% when I restart the app after a deploy.

What could be causing this? I have Rails 3.2.6, Ubuntu 12.04, MySQL 5.1.63

like image 254
Jakub Arnold Avatar asked Nov 13 '22 01:11

Jakub Arnold


1 Answers

I was having a similar problem in the recent weeks, and had no idea where it came from. Yesterday I tweaked unicorn configuration (our server is running on Debian + unicorn + MySQL), changed number of workers to 4, and limit number of concurrent connections per worker to 2 (in config/database.yml). This morning I find the problem gone, no more random exception like this happens. So I guess it was because too much concurrent connections made MySQL unstable.

I've just posted on my blog about it. Hope this can help you as well.

like image 148
ZelluX Avatar answered Dec 22 '22 12:12

ZelluX