rails 4升级后的mysql错误

时间:2014-01-21 05:28:45

标签: mysql ruby-on-rails ruby rspec ruby-on-rails-4

我已经将应用程序从rails 3.2更新到rails 4.0.2,当我运行rspec时,我似乎得到了随机的mysql错误。在rails 4升级之前没有发生这种情况。

环境详情:

  • Mac OSX
  • ruby​​ 2.0
  • Rails 4.0.2
  • mysql2 gem

错误:

ActiveRecord::StatementInvalid:
   Mysql2::Error: MySQL server has gone away: SELECT 

更新:在运行rake任务时在heroku上遇到类似的问题

堆栈追踪:

Mysql2::Error: Lost connection to MySQL server during query: SELECT ....
   (0.1ms)  ROLLBACK
Mysql2::Error: MySQL server has gone away: ROLLBACK
rake aborted!
Mysql2::Error: Lost connection to MySQL server during query: SELECT  ...
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:287:in `query'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:287:in `block in execute'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:435:in `block in log'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:430:in `log'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:287:in `execute'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/mysql2_adapter.rb:222:in `execute'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/mysql2_adapter.rb:226:in `exec_query'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/mysql2_adapter.rb:235:in `select'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:24:in `select_all'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/querying.rb:36:in `find_by_sql'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/relation.rb:585:in `exec_queries'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/relation.rb:471:in `load'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/relation.rb:220:in `to_a'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/relation.rb:598:in `exec_queries'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/association_relation.rb:15:in `exec_queries'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/relation.rb:471:in `load'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/relation.rb:220:in `to_a'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/relation/finder_methods.rb:325:in `find_first'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/relation/finder_methods.rb:90:in `first'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-deprecated_finders-1.0.3/lib/active_record/deprecated_finders/relation.rb:129:in `first'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/associations/singular_association.rb:42:in `find_target'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/associations/association.rb:147:in `load_target'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/associations/association.rb:54:in `reload'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/associations/singular_association.rb:9:in `reader'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/associations/builder/association.rb:70:in `assessment'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/associations/builder/belongs_to.rb:28:in `belongs_to_counter_cache_after_create_for_assessment'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/callbacks.rb:375:in `_run__4224105350082465631__create__callbacks'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/callbacks.rb:80:in `run_callbacks'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/callbacks.rb:306:in `create_record'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/timestamp.rb:57:in `create_record'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/persistence.rb:477:in `create_or_update'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/callbacks.rb:302:in `block in create_or_update'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/callbacks.rb:403:in `_run__4224105350082465631__save__callbacks'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/callbacks.rb:80:in `run_callbacks'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/callbacks.rb:302:in `create_or_update'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/persistence.rb:128:in `save!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/validations.rb:57:in `save!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/attribute_methods/dirty.rb:41:in `save!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/transactions.rb:275:in `block in save!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/transactions.rb:326:in `block in with_transaction_returning_status'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:200:in `transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/transactions.rb:209:in `transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/transactions.rb:323:in `with_transaction_returning_status'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/transactions.rb:275:in `save!'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/associations/has_many_through_association.rb:94:in `save_through_record'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/associations/has_many_through_association.rb:65:in `insert_record'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/associations/collection_association.rb:523:in `block (2 levels) in concat_records'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/associations/collection_association.rb:367:in `add_to_target'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/associations/collection_association.rb:522:in `block in concat_records'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/associations/collection_association.rb:520:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/associations/collection_association.rb:520:in `concat_records'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/associations/has_many_through_association.rb:43:in `concat_records'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/associations/collection_association.rb:137:in `block in concat'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/associations/collection_association.rb:152:in `block in transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/transactions.rb:209:in `transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/associations/collection_association.rb:151:in `transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/associations/collection_association.rb:137:in `concat'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/associations/has_many_through_association.rb:37:in `concat'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/associations/collection_proxy.rb:943:in `<<'
/app/lib/tasks/scrape_workbook.rake:143:in `block (3 levels) in <top (required)>'
/app/vendor/bundle/ruby/2.0.0/gems/nokogiri-1.6.1/lib/nokogiri/xml/node_set.rb:237:in `block in each'
/app/vendor/bundle/ruby/2.0.0/gems/nokogiri-1.6.1/lib/nokogiri/xml/node_set.rb:236:in `upto'
/app/vendor/bundle/ruby/2.0.0/gems/nokogiri-1.6.1/lib/nokogiri/xml/node_set.rb:236:in `each'
/app/lib/tasks/scrape_workbook.rake:29:in `block (2 levels) in <top (required)>'
/app/vendor/bundle/ruby/2.0.0/gems/aws-sdk-1.32.0/lib/aws/core/collection.rb:48:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/aws-sdk-1.32.0/lib/aws/core/collection.rb:48:in `block in each'
/app/vendor/bundle/ruby/2.0.0/gems/aws-sdk-1.32.0/lib/aws/core/collection/with_limit_and_next_token.rb:61:in `_each_batch'
/app/vendor/bundle/ruby/2.0.0/gems/aws-sdk-1.32.0/lib/aws/core/collection.rb:80:in `each_batch'
/app/vendor/bundle/ruby/2.0.0/gems/aws-sdk-1.32.0/lib/aws/core/collection.rb:47:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/aws-sdk-1.32.0/lib/aws/s3/object_collection.rb:282:in `each'
/app/lib/tasks/scrape_workbook.rake:12:in `block in <top (required)>'

1 个答案:

答案 0 :(得分:0)

试试这个。

do "bundle install --without production"

看看这是否有帮助。