Ruby on Rails Errno::EPIPE Broken pipe
I know there is a lot of people posting this online but I haven't been able to find a solution.
I receive Errno::EPIPE after my website hasn't been accessed for > 6-8 hours. I read about it maybe having to do with the ruby-mysql driver, but havent found a solution. Here is the full trace. I am running a ruby on rails server on apache with passenger and mysql. Thanks for the help!!!
Errno::EPIPE Broken pipe
ruby-mysql (2.9.3) lib/mysql/protocol.rb:617:in `flush'
ruby-mysql (2.9.3) lib/mysql/protocol.rb:617:in `write'
/usr/lib/ruby/1.8/timeout.rb:53:in `timeout'
ruby-mysql (2.9.3) lib/mysql/protocol.rb:616:in `write'
ruby-mysql (2.9.3) lib/mysql/protocol.rb:640:in `simple_command'
ruby-mysql (2.9.3) lib/mysql/protocol.rb:545:in `synchronize'
ruby-mysql (2.9.3) lib/mysql/protocol.rb:638:in `simple_command'
ruby-mysql (2.9.3) lib/mysql/protocol.rb:413:in `statistics_command'
ruby-mysql (2.9.3) lib/mysql.rb:502:in `stat'
activerecord (3.0.0) lib/active_record/connection_adapters/mysql_adapter.rb:238:in `active?'
activerecord (3.0.0) lib/active_record/connection_adapters/abstract_adapter.rb:148:in `verify!'
activerecord (3.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:250:in `checkout_and_verify'
activesupport (3.0.0) lib/active_support/callbacks.rb:413:in `_run_checkout_callbacks'
activesupport (3.0.0) lib/active_support/callbacks.rb:93:in `send'
activesupport (3.0.0) lib/active_support/callbacks.rb:93:in `run_callbacks'
activerecord (3.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:249:in `checkout_and_verify'
activerecord (3.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:245:in `checkout_existing_connection'
activerecord (3.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:192:in `checkout'
activerecord (3.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:190:in `loop'
activerecord (3.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:190:in `checkout'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
activerecord (3.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:189:in `checkout'
activerecord (3.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:96:in `connection'
activerecord (3.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:318:in `retrieve_connection'
activerecord (3.0.0) lib/active_record/connection_adapters/abstract/connection_specification.rb:97:in `retrieve_connection'
activerecord (3.0.0) lib/active_record/connection_adapters/abstract/connection_specification.rb:89:in `connection'
activerecord (3.0.0) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.0) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.0) lib/active_record/connec开发者_JAVA百科tion_adapters/abstract/connection_pool.rb:355:in `call'
actionpack (3.0.0) lib/action_dispatch/middleware/callbacks.rb:46:in `call'
activesupport (3.0.0) lib/active_support/callbacks.rb:415:in `_run_call_callbacks'
actionpack (3.0.0) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.1) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.0) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.0) lib/action_dispatch/middleware/show_exceptions.rb:46:in `call'
railties (3.0.0) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.1) lib/rack/runtime.rb:17:in `call'
rack (1.2.1) lib/rack/lock.rb:11:in `call'
rack (1.2.1) lib/rack/lock.rb:11:in `synchronize'
rack (1.2.1) lib/rack/lock.rb:11:in `call'
actionpack (3.0.0) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.0) lib/rails/application.rb:168:in `call'
railties (3.0.0) lib/rails/application.rb:77:in `send'
railties (3.0.0) lib/rails/application.rb:77:in `method_missing'
passenger (3.0.0) lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
passenger (3.0.0) lib/phusion_passenger/abstract_request_handler.rb:513:in `accept_and_process_next_request'
passenger (3.0.0) lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
passenger (3.0.0) lib/phusion_passenger/classic_rails/application_spawner.rb:321:in `start_request_handler'
passenger (3.0.0) lib/phusion_passenger/classic_rails/application_spawner.rb:275:in `send'
passenger (3.0.0) lib/phusion_passenger/classic_rails/application_spawner.rb:275:in `handle_spawn_application'
passenger (3.0.0) lib/phusion_passenger/utils.rb:479:in `safe_fork'
passenger (3.0.0) lib/phusion_passenger/classic_rails/application_spawner.rb:270:in `handle_spawn_application'
passenger (3.0.0) lib/phusion_passenger/abstract_server.rb:357:in `__send__'
passenger (3.0.0) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
passenger (3.0.0) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
passenger (3.0.0) lib/phusion_passenger/abstract_server.rb:180:in `start'
passenger (3.0.0) lib/phusion_passenger/classic_rails/application_spawner.rb:149:in `start'
passenger (3.0.0) lib/phusion_passenger/spawn_manager.rb:219:in `spawn_rails_application'
passenger (3.0.0) lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
passenger (3.0.0) lib/phusion_passenger/spawn_manager.rb:214:in `spawn_rails_application'
passenger (3.0.0) lib/phusion_passenger/abstract_server_collection.rb:82:in `synchronize'
passenger (3.0.0) lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
passenger (3.0.0) lib/phusion_passenger/spawn_manager.rb:213:in `spawn_rails_application'
passenger (3.0.0) lib/phusion_passenger/spawn_manager.rb:132:in `spawn_application'
passenger (3.0.0) lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
passenger (3.0.0) lib/phusion_passenger/abstract_server.rb:357:in `__send__'
passenger (3.0.0) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
passenger (3.0.0) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
/usr/share/phusion-passenger/helper-scripts/passenger-spawn-server:99</blink>
Unless there is a special reason for you using ruby-mysql, remove it, install the 'default' mysql gem
gem install mysql2
and use that one in your Gemfile:
gem "mysql2"
According to the author of the blog mentioned by Bohdan Pohorilets, this is how the problem was solved.
I added the following to .../app/controllers/application_controller.rb
before_filter :verify_connection
def verify_connection
Product.verify_active_connections!
end
(Product is one of my models - any one should work) and this problem went away.
I had this error while was working with apple push notifications workaround from http://gaveen.owain.org/2008/04/errnoepipe-broken-pipe-mysql-error-in.html solved problem
Create a sleeper thread which would use the DB connection periodically Eg:
Thread.new do
loop do
sleep(30*60)
logger.fatal("ActiveRecord::Base.verify_active_connections!")
ActiveRecord::Base.verify_active_connections!
ActiveRecord::Base.connection.select_value('select 1')
end
end
精彩评论