Permalink
Browse files

Afer forking, correctly clear ActiveRecord connections other than the…

… default one.
  • Loading branch information...
1 parent 4a0e6ab commit 97db5072aa8e5d42ee82f7cb62c73e500309aeb6 @FooBarWidget FooBarWidget committed Jan 7, 2010
Showing with 13 additions and 3 deletions.
  1. +5 −0 NEWS
  2. +8 −3 lib/phusion_passenger/railz/application_spawner.rb
View
5 NEWS
@@ -38,6 +38,11 @@ Release 2.2.9
The Rails::Boot monkey patching code as posted at
http://yehudakatz.com/2009/11/03/using-the-new-gem-bundler-today/
does not seem to be required anymore.
+ * Fixed support for ActiveRecord subclasses that connect to another database.
+ ActiveRecord subclasses that connect to a database other than the default
+ one did not have their connection correctly cleared after forking.
+ This can result in weird errors along the lines of "Lost connection to
+ MySQL server during query". Issue #429.
* [Nginx] Fixed PCRE URL.
passenger-install-nginx-module downloads PCRE 7.8 if PCRE is not already
installed. However PCRE 7.8 has been removed from their FTP server,
@@ -367,11 +367,16 @@ def start_request_handler(channel, forked)
$0 = "Rails: #{@app_root}"
reader, writer = IO.pipe
begin
- # Re-establish connection if a connection was established
+ # Clear or re-establish connection if a connection was established
# in environment.rb. This prevents us from concurrently
# accessing the same MySQL connection handle.
- if defined?(::ActiveRecord::Base) && ::ActiveRecord::Base.connected?
- ::ActiveRecord::Base.establish_connection
+ if defined?(::ActiveRecord::Base)
+ if ::ActiveRecord::Base.respond_to?(:clear_all_connections!)
+ ::ActiveRecord::Base.clear_all_connections!
+ elsif ::ActiveRecord::Base.respond_to?(:connected?) &&
+ ::ActiveRecord::Base.connected?
+ ::ActiveRecord::Base.establish_connection
+ end
end
reader.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)

0 comments on commit 97db507

Please sign in to comment.