Browse files

Fix for propper resource freeing for Merb. Also adds propper garbage

collection for the disconnected databases.
  • Loading branch information...
1 parent a144d4c commit e733dde8dbb93912df257548981eb35696eeacb2 @pk committed Oct 1, 2009
Showing with 20 additions and 3 deletions.
  1. +20 −3 lib/merb_sequel.rb
View
23 lib/merb_sequel.rb
@@ -24,11 +24,28 @@ def self.run
end
end
+
+ # Disconnects from DB before reaping workers
+ #
+ # We must disconnect from the DB before the worker process dies to be nice
+ # and not cause IO blocking.
+ #
+ # Disconnect only when fork_for_class_relaod is set and we're not in
+ # testing mode.
+ Merb::BootLoader.before_worker_shutdown do
+ if Merb::Config[:fork_for_class_load] && !Merb.testing?
+ Merb.logger.info "Disconnecting database connection before worker shutdown..."
+ dbs = []
+ ::Sequel::DATABASES.each { |db| db.disconnect; dbs << db }
+ # Cleanup disconnected databases so they can be GCed
+ dbs.each {|db| ::Sequel::DATABASES.delete(db) }
+ end
+ end
# Disconnects from DB before starting reloading classes
#
- # There is a problem with the pg gem driver wich causes infinite loop
- # duing reloading process.
+ # We must disconnect from the DB before the worker process dies to be nice
+ # and not cause IO blocking.
#
# Disconnect only when fork_for_class_relaod is set and we're not in
# testing mode.
@@ -37,7 +54,7 @@ class Merb::BootLoader::DisconnectBeforeStartTransaction < Merb::BootLoader
def self.run
if Merb::Config[:fork_for_class_load] && !Merb.testing?
- Merb.logger.debug "Disconnecting database connection before starting transaction."
+ Merb.logger.info "Disconnecting database connection before starting transaction."
::Sequel::DATABASES.each { |db| db.disconnect }
end
end

0 comments on commit e733dde

Please sign in to comment.