mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-22 13:37:24 +00:00
Release client only when it still exists
@pool.release should not be called when the client has already been deleted from the pool.
This commit is contained in:
parent
75eb8b8d7f
commit
621c6abfe6
@ -51,21 +51,32 @@ module Invidious::ConnectionPool
|
|||||||
|
|
||||||
# Checks out a client in the pool
|
# Checks out a client in the pool
|
||||||
private def client(&)
|
private def client(&)
|
||||||
pool.checkout do |http_client|
|
# If a client has been deleted from the pool
|
||||||
# Proxy needs to be reinstated every time we get a client from the pool
|
# we won't try to release it
|
||||||
http_client.proxy = make_configured_http_proxy_client() if CONFIG.http_proxy
|
client_exists_in_pool = true
|
||||||
|
|
||||||
response = yield http_client
|
http_client = pool.checkout
|
||||||
|
|
||||||
return response
|
# Proxy needs to be reinstated every time we get a client from the pool
|
||||||
rescue ex
|
http_client.proxy = make_configured_http_proxy_client() if CONFIG.http_proxy
|
||||||
# Prevent broken client from being checked back into the pool
|
|
||||||
pool.delete(http_client)
|
response = yield http_client
|
||||||
raise ConnectionPool::Error.new(ex.message, cause: ex)
|
|
||||||
end
|
|
||||||
rescue ex : DB::PoolTimeout
|
rescue ex : DB::PoolTimeout
|
||||||
# Failed to checkout a client
|
# Failed to checkout a client
|
||||||
raise ConnectionPool::Error.new(ex.message, cause: ex)
|
raise ConnectionPool::Error.new(ex.message, cause: ex)
|
||||||
|
rescue ex
|
||||||
|
# An error occurred with the client itself.
|
||||||
|
# Delete the client from the pool and close the connection
|
||||||
|
if http_client
|
||||||
|
client_exists_in_pool = false
|
||||||
|
@pool.delete(http_client)
|
||||||
|
http_client.close
|
||||||
|
end
|
||||||
|
|
||||||
|
# Raise exception for outer methods to handle
|
||||||
|
raise ConnectionPool::Error.new(ex.message, cause: ex)
|
||||||
|
ensure
|
||||||
|
pool.release(http_client) if http_client && client_exists_in_pool
|
||||||
end
|
end
|
||||||
|
|
||||||
private def build_pool
|
private def build_pool
|
||||||
|
Loading…
Reference in New Issue
Block a user