From 4fe38848982abdb544bfb48603e9c24133039707 Mon Sep 17 00:00:00 2001 From: Cris Ward Date: Thu, 27 Jul 2017 15:08:05 +0100 Subject: [PATCH] Release connection when query cannot be built This was leaking connection when a query could not be build - ie if an invalid column name was used. More info here - https://github.com/crystal-lang/crystal-mysql/issues/40 --- src/db/pool_prepared_statement.cr | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/db/pool_prepared_statement.cr b/src/db/pool_prepared_statement.cr index d50b240..23b049d 100644 --- a/src/db/pool_prepared_statement.cr +++ b/src/db/pool_prepared_statement.cr @@ -34,7 +34,12 @@ module DB clean_connections conn, existing = @db.checkout_some(@connections) @connections << WeakRef.new(conn) unless existing - conn.prepared.build(@query) + begin + conn.prepared.build(@query) + rescue ex + conn.release + raise ex + end end private def clean_connections