diff --git a/lib/freedom_patches/pool_drainer.rb b/lib/freedom_patches/pool_drainer.rb index dc9a2f499ce..583358cc4b8 100644 --- a/lib/freedom_patches/pool_drainer.rb +++ b/lib/freedom_patches/pool_drainer.rb @@ -26,13 +26,15 @@ class ActiveRecord::ConnectionAdapters::ConnectionPool # if idle_time is specified only connections idle for N seconds will be drained def drain(idle_time = nil, max_age = nil) synchronize do - @available.clear - @connections.delete_if do |conn| - try_drain?(conn, idle_time, max_age) - end + if @available && @connections + @available.clear + @connections.delete_if do |conn| + try_drain?(conn, idle_time, max_age) + end - @connections.each do |conn| - @available.add conn if !conn.in_use? + @connections.each do |conn| + @available.add conn if !conn.in_use? + end end end