ReverseProxy: Fix a gun connection leak when there is an error with no
body - Modify `close/1` function to do the same thing it does for hackney, which is - close the client rather than the whole connection - Release the connection when there is no body to chunk
This commit is contained in:
parent
ce9647aed7
commit
d4fbec62a3
@ -5,6 +5,8 @@
|
|||||||
defmodule Pleroma.ReverseProxy.Client.Tesla do
|
defmodule Pleroma.ReverseProxy.Client.Tesla do
|
||||||
@behaviour Pleroma.ReverseProxy.Client
|
@behaviour Pleroma.ReverseProxy.Client
|
||||||
|
|
||||||
|
alias Pleroma.Gun.ConnectionPool
|
||||||
|
|
||||||
@type headers() :: [{String.t(), String.t()}]
|
@type headers() :: [{String.t(), String.t()}]
|
||||||
@type status() :: pos_integer()
|
@type status() :: pos_integer()
|
||||||
|
|
||||||
@ -31,6 +33,8 @@ defmodule Pleroma.ReverseProxy.Client.Tesla do
|
|||||||
if is_map(response.body) and method != :head do
|
if is_map(response.body) and method != :head do
|
||||||
{:ok, response.status, response.headers, response.body}
|
{:ok, response.status, response.headers, response.body}
|
||||||
else
|
else
|
||||||
|
conn_pid = response.opts[:adapter][:conn]
|
||||||
|
ConnectionPool.release_conn(conn_pid)
|
||||||
{:ok, response.status, response.headers}
|
{:ok, response.status, response.headers}
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@ -48,7 +52,7 @@ defmodule Pleroma.ReverseProxy.Client.Tesla do
|
|||||||
# if there were redirects we need to checkout old conn
|
# if there were redirects we need to checkout old conn
|
||||||
conn = opts[:old_conn] || opts[:conn]
|
conn = opts[:old_conn] || opts[:conn]
|
||||||
|
|
||||||
if conn, do: :ok = Pleroma.Gun.ConnectionPool.release_conn(conn)
|
if conn, do: :ok = ConnectionPool.release_conn(conn)
|
||||||
|
|
||||||
:done
|
:done
|
||||||
end
|
end
|
||||||
@ -74,8 +78,7 @@ defmodule Pleroma.ReverseProxy.Client.Tesla do
|
|||||||
@impl true
|
@impl true
|
||||||
@spec close(map) :: :ok | no_return()
|
@spec close(map) :: :ok | no_return()
|
||||||
def close(%{pid: pid}) do
|
def close(%{pid: pid}) do
|
||||||
adapter = check_adapter()
|
ConnectionPool.release_conn(pid)
|
||||||
adapter.close(pid)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp check_adapter do
|
defp check_adapter do
|
||||||
|
@ -165,6 +165,9 @@ defmodule Pleroma.ReverseProxy do
|
|||||||
{:ok, code, _, _} ->
|
{:ok, code, _, _} ->
|
||||||
{:error, {:invalid_http_response, code}}
|
{:error, {:invalid_http_response, code}}
|
||||||
|
|
||||||
|
{:ok, code, _} ->
|
||||||
|
{:error, {:invalid_http_response, code}}
|
||||||
|
|
||||||
{:error, error} ->
|
{:error, error} ->
|
||||||
{:error, error}
|
{:error, error}
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user