Jakub Arnold
Jakub Arnold

Reputation: 87270

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

Upvotes: 5

Views: 558

Answers (2)

ZelluX
ZelluX

Reputation: 72795

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.

Upvotes: 1

Noah
Noah

Reputation: 1966

Error seems to indicate that there is a missing 'attribute'. Does both your db schema and your class structure handle a 'created_at' variable or column? I would look specifically at the User class/table.

Upvotes: 0

Related Questions