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
This commit is contained in:
Cris Ward 2017-07-27 15:08:05 +01:00 committed by GitHub
parent 28c6f3b715
commit 4fe3884898
1 changed files with 6 additions and 1 deletions

View File

@ -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