Ruby on Rails Errno::EPIPE Broken pipe
Asked Answered
X

3

8

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/connection_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>
Xanthippe answered 4/12, 2010 at 2:35 Comment(2)
I'm seeing exactly the same behavior running Redmine under Passenger 3.0.7, Rails 2.3.11, and Rack 1.1.1. I've tried using various MySQL gems (mysql, ruby-mysql, mysql2) and added all kinds of extra specifications to control Passenger's connection pool idle time and pool size to no avail. Lots of people seem to run into this issue, but I have yet to find a viable solution.Agnostic
Are any of the three given answers the answer? If so, please mark the answerPattiepattin
P
5

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.

Pattiepattin answered 10/8, 2011 at 13:54 Comment(0)
G
1

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.

Grice answered 30/12, 2010 at 21:55 Comment(1)
Still seems to fail. Thanks for the suggestion!Xanthippe
M
0

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
Morra answered 10/8, 2011 at 10:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.