Method: ActiveRecord::ConnectionAdapters::ConnectionPool#reap

Defined in:
activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb

#reapObject

Recover lost connections for the pool. A lost connection can occur if a programmer forgets to checkin a connection at the end of a thread or a thread dies unexpectedly.



625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
# File 'activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb', line 625

def reap
  stale_connections = synchronize do
    return if self.discarded?
    @connections.select do |conn|
      conn.in_use? && !conn.owner.alive?
    end.each do |conn|
      conn.steal!
    end
  end

  stale_connections.each do |conn|
    if conn.active?
      conn.reset!
      checkin conn
    else
      remove conn
    end
  end
end