Connection Pool: don't enforce pool limits if no new connection needs to be opened

This commit is contained in:
rinpatch 2020-05-06 21:41:34 +03:00
parent 58a4f350a8
commit fffbcffb8c
1 changed files with 14 additions and 14 deletions

View File

@ -2,20 +2,20 @@ defmodule Pleroma.Gun.ConnectionPool do
@registry __MODULE__ @registry __MODULE__
def get_conn(uri, opts) do def get_conn(uri, opts) do
case enforce_pool_limits() do key = "#{uri.scheme}:#{uri.host}:#{uri.port}"
:ok ->
key = "#{uri.scheme}:#{uri.host}:#{uri.port}"
case Registry.lookup(@registry, key) do case Registry.lookup(@registry, key) do
# The key has already been registered, but connection is not up yet # The key has already been registered, but connection is not up yet
[{worker_pid, {nil, _used_by, _crf, _last_reference}}] -> [{worker_pid, {nil, _used_by, _crf, _last_reference}}] ->
get_gun_pid_from_worker(worker_pid) get_gun_pid_from_worker(worker_pid)
[{worker_pid, {gun_pid, _used_by, _crf, _last_reference}}] -> [{worker_pid, {gun_pid, _used_by, _crf, _last_reference}}] ->
GenServer.cast(worker_pid, {:add_client, self(), false}) GenServer.cast(worker_pid, {:add_client, self(), false})
{:ok, gun_pid} {:ok, gun_pid}
[] -> [] ->
case enforce_pool_limits() do
:ok ->
# :gun.set_owner fails in :connected state for whatevever reason, # :gun.set_owner fails in :connected state for whatevever reason,
# so we open the connection in the process directly and send it's pid back # so we open the connection in the process directly and send it's pid back
# We trust gun to handle timeouts by itself # We trust gun to handle timeouts by itself
@ -33,10 +33,10 @@ def get_conn(uri, opts) do
err -> err ->
err err
end end
end
:error -> :error ->
{:error, :pool_full} {:error, :pool_full}
end
end end
end end