Ir al contenido

Db Connection Not Closed (ARCH6084)

Esta página aún no está disponible en tu idioma.

Key ruby.performance.db-connection-not-closed · Severity error · Category performance

A database connection or cursor that is opened but never closed exhausts the pool and later requests block waiting for a connection. Manage the connection with the block form.

def count_users(pool)
conn = pool.checkout
conn.exec("SELECT COUNT(*) FROM users").first
end
def count_users(pool)
pool.with do |conn|
conn.exec("SELECT COUNT(*) FROM users").first
end
end

Manage connections and cursors with a block/ensure form and return them to the pool when done.