mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
feat(error): close resources on resource lost (#155)
This commit is contained in:
parent
6dc3f2dd6f
commit
a25f33611c
3 changed files with 21 additions and 3 deletions
|
@ -18,6 +18,7 @@ module DB
|
|||
getter resource : T
|
||||
|
||||
def initialize(@resource : T)
|
||||
@resource.close
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -179,10 +179,12 @@ module DB
|
|||
sleep @retry_delay if i >= current_available
|
||||
return yield
|
||||
rescue e : PoolResourceLost(T)
|
||||
# if the connection is lost close it to release resources
|
||||
# and remove it from the known pool.
|
||||
# if the connection is lost it will be closed by
|
||||
# the exception to release resources
|
||||
# we still need to remove it from the known pool.
|
||||
# Closed connection will be evicted from statement cache
|
||||
# in PoolPreparedStatement#clean_connections
|
||||
sync { delete(e.resource) }
|
||||
e.resource.close
|
||||
rescue e : PoolResourceRefused
|
||||
# a ConnectionRefused means a new connection
|
||||
# was intended to be created
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue