Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Afer forking, correctly clear ActiveRecord connections other than the…

… default one.
  • Loading branch information...
commit 97db5072aa8e5d42ee82f7cb62c73e500309aeb6 1 parent 4a0e6ab
Hongli Lai authored January 07, 2010
5  NEWS
@@ -38,6 +38,11 @@ Release 2.2.9
38 38
    The Rails::Boot monkey patching code as posted at
39 39
    http://yehudakatz.com/2009/11/03/using-the-new-gem-bundler-today/
40 40
    does not seem to be required anymore.
  41
+ * Fixed support for ActiveRecord subclasses that connect to another database.
  42
+   ActiveRecord subclasses that connect to a database other than the default
  43
+   one did not have their connection correctly cleared after forking.
  44
+   This can result in weird errors along the lines of "Lost connection to
  45
+   MySQL server during query". Issue #429.
41 46
  * [Nginx] Fixed PCRE URL.
42 47
    passenger-install-nginx-module downloads PCRE 7.8 if PCRE is not already
43 48
    installed. However PCRE 7.8 has been removed from their FTP server,
11  lib/phusion_passenger/railz/application_spawner.rb
@@ -367,11 +367,16 @@ def start_request_handler(channel, forked)
367 367
 		$0 = "Rails: #{@app_root}"
368 368
 		reader, writer = IO.pipe
369 369
 		begin
370  
-			# Re-establish connection if a connection was established
  370
+			# Clear or re-establish connection if a connection was established
371 371
 			# in environment.rb. This prevents us from concurrently
372 372
 			# accessing the same MySQL connection handle.
373  
-			if defined?(::ActiveRecord::Base) && ::ActiveRecord::Base.connected?
374  
-				::ActiveRecord::Base.establish_connection
  373
+			if defined?(::ActiveRecord::Base)
  374
+				if ::ActiveRecord::Base.respond_to?(:clear_all_connections!)
  375
+					::ActiveRecord::Base.clear_all_connections!
  376
+				elsif ::ActiveRecord::Base.respond_to?(:connected?) &&
  377
+				      ::ActiveRecord::Base.connected?
  378
+					::ActiveRecord::Base.establish_connection
  379
+				end
375 380
 			end
376 381
 			
377 382
 			reader.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)

0 notes on commit 97db507

Please sign in to comment.
Something went wrong with that request. Please try again.