简体   繁体   English

第一次运行Rails应用程序时抛出数据库错误,重新加载时可以正常运行

[英]Database error thrown the first time my Rails app is run, fine on reload

I think this all started around the time my host (Bluehost) upgraded their RoR to version 3. 我认为这一切都是在我的主机(Bluehost)将RoR升级到版本3的时候开始的。

The first time I run my app after a hours of it not being accessed it throws an error (see below). 一个小时没有访问我的应用后,我第一次运行它会引发错误(请参见下文)。 If I reload, the error goes away and the database access works as expected. 如果重新加载,该错误​​将消失,数据库访问将按预期进行。

I thought it might be the version of ActiveRecord, but it looks as if the Bluehost is using its own version (3.2.13) and not the version I installed in my config (4.2.1). 我以为它可能是ActiveRecord的版本,但它看起来好像Bluehost正在使用其自己的版本(3.2.13),而不是我在配置中安装的版本(4.2.1)。

I suspect it might be something to do with Phusion Passenger and caching connections, but I'm not sure how to diagnose or fix that. 我怀疑这可能与Phusion Passenger和缓存连接有关,但是我不确定如何诊断或修复它。

Any pointers greatly appreciated. 任何指针,不胜感激。

According to command line: 根据命令行:

Ruby version: 1.9.3p429 Rails version: 3.2.13 Ruby版本:1.9.3p429 Rails版本:3.2.13

Connecting to database specified by database.yml
Started GET "/" for xx.xx.xx.xxx at 2015-04-30 17:00:52 -0600

TypeError (can't convert nil into String):
  mysql2 (0.3.11) lib/mysql2/client.rb:20:in `init_connection'
  mysql2 (0.3.11) lib/mysql2/client.rb:20:in `initialize'
  activerecord (3.2.13) lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `new'
  activerecord (3.2.13) lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `mysql2_connection'
  activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection'
  activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'
  activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block (2 levels) in checkout'
  activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'
  activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block in checkout'
  /usr/lib64/ruby/1.9.3/monitor.rb:211:in `mon_synchronize'
  activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checkout'
  activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block in connection'
  /usr/lib64/ruby/1.9.3/monitor.rb:211:in `mon_synchronize'
  activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connection'
  activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
  activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
  activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
  activerecord (3.2.13) lib/active_record/query_cache.rb:61:in `call'
  activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `_run__3881617127537431469__call__281038867919454016__callbacks'
  activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.13) lib/rails/rack/logger.rb:32:in `call_app'
  railties (3.2.13) lib/rails/rack/logger.rb:16:in `block in call'
  activesupport (3.2.13) lib/active_support/tagged_logging.rb:22:in `tagged'
  railties (3.2.13) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.5) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.13) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.5) lib/rack/lock.rb:15:in `call'
  rack-cache (1.2) lib/rack/cache/context.rb:136:in `forward'
  rack-cache (1.2) lib/rack/cache/context.rb:245:in `fetch'
  rack-cache (1.2) lib/rack/cache/context.rb:185:in `lookup'
  rack-cache (1.2) lib/rack/cache/context.rb:66:in `call!'
  rack-cache (1.2) lib/rack/cache/context.rb:51:in `call'
  railties (3.2.13) lib/rails/engine.rb:479:in `call'
  railties (3.2.13) lib/rails/application.rb:223:in `call'
  railties (3.2.13) lib/rails/railtie/configurable.rb:30:in `method_missing'
  /etc/httpd/modules/passenger/lib/phusion_passenger/rack/request_handler.rb:97:in `process_request'
  /etc/httpd/modules/passenger/lib/phusion_passenger/abstract_request_handler.rb:520:in `accept_and_process_next_request'
  /etc/httpd/modules/passenger/lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
  /etc/httpd/modules/passenger/lib/phusion_passenger/rack/application_spawner.rb:206:in `start_request_handler'
  /etc/httpd/modules/passenger/lib/phusion_passenger/rack/application_spawner.rb:171:in `block in handle_spawn_application'
  /etc/httpd/modules/passenger/lib/phusion_passenger/utils.rb:470:in `safe_fork'
  /etc/httpd/modules/passenger/lib/phusion_passenger/rack/application_spawner.rb:166:in `handle_spawn_application'
  /etc/httpd/modules/passenger/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
  /etc/httpd/modules/passenger/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
  /etc/httpd/modules/passenger/lib/phusion_passenger/abstract_server.rb:180:in `start'
  /etc/httpd/modules/passenger/lib/phusion_passenger/rack/application_spawner.rb:129:in `start'
  /etc/httpd/modules/passenger/lib/phusion_passenger/spawn_manager.rb:253:in `block (2 levels) in spawn_rack_application'
  /etc/httpd/modules/passenger/lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
  /etc/httpd/modules/passenger/lib/phusion_passenger/spawn_manager.rb:246:in `block in spawn_rack_application'
  /etc/httpd/modules/passenger/lib/phusion_passenger/abstract_server_collection.rb:82:in `block in synchronize'
  <internal:prelude>:10:in `synchronize'
  /etc/httpd/modules/passenger/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
  /etc/httpd/modules/passenger/lib/phusion_passenger/spawn_manager.rb:244:in `spawn_rack_application'
  /etc/httpd/modules/passenger/lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application'
  /etc/httpd/modules/passenger/lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
  /etc/httpd/modules/passenger/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
  /etc/httpd/modules/passenger/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
  /etc/httpd/modules/passenger/helper-scripts/passenger-spawn-server:99:in `<main>'

it looks as if the Bluehost is using its own version (3.2.13) and not the version I installed in my config (4.2.1) 它看起来好像Bluehost正在使用其自己的版本(3.2.13),而不是我在配置中安装的版本(4.2.1)

If this is really the case, that your hosting provider is using Rails 3.2.13 when you've specified 4.2.1 in your Gemfile / Gemfile.lock then get a new hosting provider, and for two reasons. 如果确实如此,那么当您在Gemfile / Gemfile.lock指定4.2.1时,您的托管服务提供商正在使用Rails 3.2.13,然后获得一个新的托管服务提供商,这有两个原因。

First, obviously, you need to be able to ship the version of the app that you know works locally. 首先,显然,您需要能够交付您知道可以在本地运行的应用程序的版本。

Second, any hosting provider who has 3.2.13 as the default Rails version should go out of business immediately. 其次,任何具有3.2.13作为默认Rails版本的托管服务提供商都应立即停业。 There are security issues fixed in the patches up to 3.2.21 and the whole 3.2 series is no longer supported for any fixes except the most severe security issues. 在最高至3.2.21的补丁程序中已修复了安全性问题,并且除最严重的安全性问题外,不再支持整个3.2系列的任何修复程序。

In summary - I suspect that your problem is being caused by the hosting provider's configuration. 总结-我怀疑您的问题是由托管服务提供商的配置引起的。 Maybe talk to them to see if there's some mis-configuration for your app/server, otherwise move to someone else. 也许与他们交谈以了解您的应用程序/服务器是否配置有误,否则请转移到其他人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM