remove connection from pool if explicitly closed

This commit is contained in:
Brian J. Cardiff 2016-09-13 01:36:49 -03:00
parent ea2a107069
commit a62c90d092
2 changed files with 9 additions and 3 deletions

View file

@ -38,6 +38,7 @@ module DB
protected def do_close protected def do_close
@statements_cache.each_value &.close @statements_cache.each_value &.close
@statements_cache.clear @statements_cache.clear
@database.pool.delete self
end end
end end
end end

View file

@ -88,8 +88,7 @@ module DB
rescue e : ConnectionLost rescue e : ConnectionLost
# if the connection is lost close it to release resources # if the connection is lost close it to release resources
# and remove it from the known pool. # and remove it from the known pool.
@total.delete(e.connection) delete(e.connection)
@available.delete(e.connection)
e.connection.close e.connection.close
end end
end end
@ -103,11 +102,17 @@ module DB
end end
end end
# :nodon: # :nodoc:
def is_available?(resource : T) def is_available?(resource : T)
@available.includes?(resource) @available.includes?(resource)
end end
# :nodoc:
def delete(resource : T)
@total.delete(resource)
@available.delete(resource)
end
private def build_resource : T private def build_resource : T
resource = @factory.call resource = @factory.call
@total << resource @total << resource