-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Errno::EPIPE in Mysql::Protocol.write #3
Comments
I edited description to put <pre>. |
It seems that the code use fork. Example: $ ruby -rmysql -e 'm=Mysql.new("localhost","user","passwd"); fork{}; sleep 1; m.query("select 123").fetch_row' -e:1:in `query': MySQL server has gone away (Mysql::Error) from -e:1 |
Yes, I'm using unicorn in a pre-forking way. It's not copy-on-write friendly, but I use the standard way to restart database connections: preload_app true before_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! end after_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection end In theory it closes database connections before forking, and re-establishes them in children. |
After re-reading your example, I found out that you get a standard Mysql::Error, and not Errno::EPIPE. Mysql::Error is handled by rails' mysql connection management, but there's a special case in ActiveRecord::ConnectionAdapters::MysqlAdapter#active? method, which explicitely states: "mysql-ruby doesn't raise an exception when stat fails", and tries to return with @connection.errno.zero?. I think there're three possible solutions for this:
I think the second one would be the best choice. |
When I try to connect to a rails app after a while (no other users, using rails 2.3.5, unicorn, ruby-mysql, with mysql server version 5.1.41 using tcp sockets), the first heartbeat (active? call from ActiveRecord's mysql adapter) runs into a broken pipe error.
I haven't found yet why TCPSocket#flush returns EPIPE on FreeBSD, but nevertheless it would be great to have a graceful handling of this error too.
Here's the backtrace:
and this is my rake gems output (version names added by me):
I'm using unicorn 0.97.0 with ruby 1.9.1p376 built from FreeBSD ports tree.
The text was updated successfully, but these errors were encountered: