diff options
author | Alexander Strizhakov <alex.strizhakov@gmail.com> | 2020-04-30 15:07:21 +0300 |
---|---|---|
committer | Alexander Strizhakov <alex.strizhakov@gmail.com> | 2020-05-06 13:25:50 +0300 |
commit | a16fb7c35c3b556c28b8e7ad708f6129b2aad161 (patch) | |
tree | d6f4bfdfc4bcbb311f8de8c6978a1f0cf0943019 /lib/pleroma | |
parent | 8e4bd2c1cf0e0570d1e3a1180d8b8a25f1425cc2 (diff) | |
download | pleroma-gun-memory-leak.tar.gz |
clean up and test coveragegun-memory-leak
Diffstat (limited to 'lib/pleroma')
-rw-r--r-- | lib/pleroma/gun/conn.ex | 9 | ||||
-rw-r--r-- | lib/pleroma/http/middleware/follow_redirects.ex | 1 | ||||
-rw-r--r-- | lib/pleroma/pool/connections.ex | 22 | ||||
-rw-r--r-- | lib/pleroma/pool/supervisor.ex | 3 | ||||
-rw-r--r-- | lib/pleroma/reverse_proxy/client/tesla.ex | 2 |
5 files changed, 14 insertions, 23 deletions
diff --git a/lib/pleroma/gun/conn.ex b/lib/pleroma/gun/conn.ex index de3173351..fb7153a16 100644 --- a/lib/pleroma/gun/conn.ex +++ b/lib/pleroma/gun/conn.ex @@ -34,11 +34,8 @@ defmodule Pleroma.Gun.Conn do crf: 1, retries: 0 - @spec open(String.t() | URI.t(), atom(), keyword()) :: :ok | nil - def open(url, name, opts \\ []) - def open(url, name, opts) when is_binary(url), do: open(URI.parse(url), name, opts) - - def open(%URI{} = uri, name, opts) do + @spec open(URI.t(), atom(), keyword()) :: :ok + def open(%URI{} = uri, name, opts \\ []) do pool_opts = Pleroma.Config.get([:connections_pool], []) opts = @@ -62,7 +59,7 @@ defmodule Pleroma.Gun.Conn do end defp try_open(name, uri, opts, max_connections) do - if Connections.count(name) < max_connections do + if Connections.count(name) <= max_connections do do_open(uri, opts) else close_least_used_and_do_open(name, uri, opts) diff --git a/lib/pleroma/http/middleware/follow_redirects.ex b/lib/pleroma/http/middleware/follow_redirects.ex index bed3ec9a0..c81755a48 100644 --- a/lib/pleroma/http/middleware/follow_redirects.ex +++ b/lib/pleroma/http/middleware/follow_redirects.ex @@ -1,4 +1,5 @@ # Pleroma: A lightweight social networking server +# Copyright © 2015-2020 Tymon Tobolski <https://github.com/teamon/tesla/blob/master/lib/tesla/middleware/follow_redirects.ex> # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> # SPDX-License-Identifier: AGPL-3.0-only diff --git a/lib/pleroma/pool/connections.ex b/lib/pleroma/pool/connections.ex index 86bb00bc5..87fa50a22 100644 --- a/lib/pleroma/pool/connections.ex +++ b/lib/pleroma/pool/connections.ex @@ -16,21 +16,20 @@ defmodule Pleroma.Pool.Connections do @type seconds :: pos_integer() @type t :: %__MODULE__{ - conns: %{domain() => conn()}, - opts: keyword() + conns: %{domain() => conn()} } - defstruct conns: %{}, opts: [] + defstruct conns: %{} - @spec start_link({atom(), keyword()}) :: {:ok, pid()} - def start_link({name, opts}) do - GenServer.start_link(__MODULE__, opts, name: name) + @spec start_link(atom()) :: {:ok, pid()} + def start_link(name) do + GenServer.start_link(__MODULE__, [], name: name) end @impl true - def init(opts) do + def init(_) do schedule_close_idle_conns() - {:ok, %__MODULE__{conns: %{}, opts: opts}} + {:ok, %__MODULE__{conns: %{}}} end @spec checkin(String.t() | URI.t(), atom()) :: pid() | nil @@ -43,11 +42,8 @@ defmodule Pleroma.Pool.Connections do @spec alive?(atom()) :: boolean() def alive?(name) do - if pid = Process.whereis(name) do - Process.alive?(pid) - else - false - end + pid = Process.whereis(name) + is_pid(pid) and Process.alive?(pid) end @spec get_state(atom()) :: t() diff --git a/lib/pleroma/pool/supervisor.ex b/lib/pleroma/pool/supervisor.ex index faf646cb2..5e200259d 100644 --- a/lib/pleroma/pool/supervisor.ex +++ b/lib/pleroma/pool/supervisor.ex @@ -15,8 +15,7 @@ defmodule Pleroma.Pool.Supervisor do def init(_) do conns_child = %{ id: Pool.Connections, - start: - {Pool.Connections, :start_link, [{:gun_connections, Config.get([:connections_pool])}]} + start: {Pool.Connections, :start_link, [:gun_connections]} } Supervisor.init([conns_child | pools()], strategy: :one_for_one) diff --git a/lib/pleroma/reverse_proxy/client/tesla.ex b/lib/pleroma/reverse_proxy/client/tesla.ex index 999b1a4cb..50736dabb 100644 --- a/lib/pleroma/reverse_proxy/client/tesla.ex +++ b/lib/pleroma/reverse_proxy/client/tesla.ex @@ -33,8 +33,6 @@ defmodule Pleroma.ReverseProxy.Client.Tesla do else {:ok, response.status, response.headers} end - else - {:error, error} -> {:error, error} end end |