summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Roth <omarroth@protonmail.com>2019-10-25 23:06:08 -0400
committerOmar Roth <omarroth@protonmail.com>2019-10-25 23:06:08 -0400
commit202de1436d812428efbee5f11a2eb60830112800 (patch)
tree392e0f784eae2076009e2a93a15de05b24f4da11
parent7f8746fcd481a3f75f6a30658e3bfeeff0eb3fbd (diff)
downloadinvidious-202de1436d812428efbee5f11a2eb60830112800.tar.gz
invidious-202de1436d812428efbee5f11a2eb60830112800.tar.bz2
invidious-202de1436d812428efbee5f11a2eb60830112800.zip
Fix broken connections in pool
-rw-r--r--src/invidious/helpers/utils.cr26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr
index 2e802051..5ddc8375 100644
--- a/src/invidious/helpers/utils.cr
+++ b/src/invidious/helpers/utils.cr
@@ -1595,7 +1595,9 @@ struct HTTPPool
end
def client(region = nil, &block)
- pool.connection do |conn|
+ conn = pool.checkout
+
+ begin
if region
PROXY_LIST[region]?.try &.sample(40).each do |proxy|
begin
@@ -1607,17 +1609,17 @@ struct HTTPPool
end
end
- begin
- response = yield conn
- conn.unset_proxy
- response
- rescue ex
- conn = HTTPClient.new(url)
- conn.family = (url.host == "www.youtube.com") ? CONFIG.force_resolve : Socket::Family::UNSPEC
- conn.read_timeout = 5.seconds
- conn.connect_timeout = 5.seconds
- yield conn
- end
+ response = yield conn
+ conn.unset_proxy
+ response
+ rescue ex
+ conn = HTTPClient.new(url)
+ conn.family = (url.host == "www.youtube.com") ? CONFIG.force_resolve : Socket::Family::UNSPEC
+ conn.read_timeout = 5.seconds
+ conn.connect_timeout = 5.seconds
+ yield conn
+ ensure
+ pool.checkin(conn)
end
end