logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git
commit: fee1e17d877e8b056020d4ffabedf9c434ae2c57
parent 1071632a501238b13593f68e2e4625e25ecd465f
Author: feld <feld@feld.me>
Date:   Thu, 20 Jun 2024 18:50:07 +0000

Merge branch 'erratic/gun' into 'develop'

Gun Connection Pool: successfully retry after reclaiming the pool

See merge request pleroma/pleroma!4154

Diffstat:

Achangelog.d/gun_pool4.fix1+
Mlib/pleroma/gun/connection_pool/reclaimer.ex2+-
Mlib/pleroma/gun/connection_pool/worker_supervisor.ex32+++++++++++++++++++++-----------
Mtest/pleroma/gun/connection_pool_test.exs1-
4 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/changelog.d/gun_pool4.fix b/changelog.d/gun_pool4.fix @@ -0,0 +1 @@ +Gun Connection Pool was not retrying to acquire a connection if the pool was full and stale connections were reclaimed diff --git a/lib/pleroma/gun/connection_pool/reclaimer.ex b/lib/pleroma/gun/connection_pool/reclaimer.ex @@ -9,7 +9,7 @@ defmodule Pleroma.Gun.ConnectionPool.Reclaimer do def start_monitor do pid = - case GenServer.start_link(__MODULE__, [], name: {:via, Registry, {registry(), "reclaimer"}}) do + case GenServer.start(__MODULE__, [], name: {:via, Registry, {registry(), "reclaimer"}}) do {:ok, pid} -> pid diff --git a/lib/pleroma/gun/connection_pool/worker_supervisor.ex b/lib/pleroma/gun/connection_pool/worker_supervisor.ex @@ -5,6 +5,9 @@ defmodule Pleroma.Gun.ConnectionPool.WorkerSupervisor do @moduledoc "Supervisor for pool workers. Does not do anything except enforce max connection limit" + alias Pleroma.Config + alias Pleroma.Gun.ConnectionPool.Worker + use DynamicSupervisor def start_link(opts) do @@ -14,21 +17,28 @@ defmodule Pleroma.Gun.ConnectionPool.WorkerSupervisor do def init(_opts) do DynamicSupervisor.init( strategy: :one_for_one, - max_children: Pleroma.Config.get([:connections_pool, :max_connections]) + max_children: Config.get([:connections_pool, :max_connections]) ) end - def start_worker(opts, last_attempt \\ false) do - case DynamicSupervisor.start_child(__MODULE__, {Pleroma.Gun.ConnectionPool.Worker, opts}) do + def start_worker(opts, last_attempt \\ false) + + def start_worker(opts, true) do + case DynamicSupervisor.start_child(__MODULE__, {Worker, opts}) do + {:error, :max_children} -> + :telemetry.execute([:pleroma, :connection_pool, :provision_failure], %{opts: opts}) + {:error, :pool_full} + + res -> + res + end + end + + def start_worker(opts, false) do + case DynamicSupervisor.start_child(__MODULE__, {Worker, opts}) do {:error, :max_children} -> - funs = [fn -> last_attempt end, fn -> match?(:error, free_pool()) end] - - if Enum.any?(funs, fn fun -> fun.() end) do - :telemetry.execute([:pleroma, :connection_pool, :provision_failure], %{opts: opts}) - {:error, :pool_full} - else - start_worker(opts, true) - end + free_pool() + start_worker(opts, true) res -> res diff --git a/test/pleroma/gun/connection_pool_test.exs b/test/pleroma/gun/connection_pool_test.exs @@ -46,7 +46,6 @@ defmodule Pleroma.Gun.ConnectionPoolTest do end end - @tag :erratic test "connection limit is respected with concurrent requests" do clear_config([:connections_pool, :max_connections]) do clear_config([:connections_pool, :max_connections], 1)