diff options
| author | feld <feld@feld.me> | 2024-06-20 18:50:07 +0000 | 
|---|---|---|
| committer | feld <feld@feld.me> | 2024-06-20 18:50:07 +0000 | 
| commit | fee1e17d877e8b056020d4ffabedf9c434ae2c57 (patch) | |
| tree | 861a9634edbb3bbaf50f2b03513c88f4a58b85a8 /lib | |
| parent | 1071632a501238b13593f68e2e4625e25ecd465f (diff) | |
| parent | 9ef021e2dae1a0bc07e997489304875b0d45ec07 (diff) | |
| download | pleroma-fee1e17d877e8b056020d4ffabedf9c434ae2c57.tar.gz pleroma-fee1e17d877e8b056020d4ffabedf9c434ae2c57.zip | |
Merge branch 'erratic/gun' into 'develop'
Gun Connection Pool: successfully retry after reclaiming the pool
See merge request pleroma/pleroma!4154
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/pleroma/gun/connection_pool/reclaimer.ex | 2 | ||||
| -rw-r--r-- | lib/pleroma/gun/connection_pool/worker_supervisor.ex | 32 | 
2 files changed, 22 insertions, 12 deletions
| diff --git a/lib/pleroma/gun/connection_pool/reclaimer.ex b/lib/pleroma/gun/connection_pool/reclaimer.ex index 35e7f4b2e..3580d38f5 100644 --- 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 index eb83962d8..b9dedf61e 100644 --- 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 | 
