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

View file

@ -34,7 +34,12 @@ module DB
clean_connections clean_connections
conn, existing = @db.checkout_some(@connections) conn, existing = @db.checkout_some(@connections)
@connections << WeakRef.new(conn) unless existing @connections << WeakRef.new(conn) unless existing
begin
conn.prepared.build(@query) conn.prepared.build(@query)
rescue ex
conn.release
raise ex
end
end end
private def clean_connections private def clean_connections