From 966b5ac42b1efd4dd03225d91c6e83ef35218f45 Mon Sep 17 00:00:00 2001 From: "Brian J. Cardiff" Date: Thu, 7 Sep 2017 19:29:32 -0300 Subject: [PATCH] Avoid tracking the connection if the statement failed to be built --- src/db/pool_prepared_statement.cr | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/db/pool_prepared_statement.cr b/src/db/pool_prepared_statement.cr index e3241e5..5a65910 100644 --- a/src/db/pool_prepared_statement.cr +++ b/src/db/pool_prepared_statement.cr @@ -33,13 +33,14 @@ module DB private def build_statement clean_connections conn, existing = @db.checkout_some(@connections) - @connections << WeakRef.new(conn) unless existing begin - conn.prepared.build(@query) + stmt = conn.prepared.build(@query) rescue ex conn.release raise ex end + @connections << WeakRef.new(conn) unless existing + stmt end private def clean_connections