diff options
author | Mark Felder <feld@feld.me> | 2024-06-20 14:03:22 -0400 |
---|---|---|
committer | Mark Felder <feld@feld.me> | 2024-06-20 14:03:22 -0400 |
commit | c765fcbe7e907dd5ac1f8b559bf65ab477dfe0f0 (patch) | |
tree | 51be39289cc9c81df0be17edde1087c8e08e4087 /lib | |
parent | 1071632a501238b13593f68e2e4625e25ecd465f (diff) | |
download | pleroma-c765fcbe7e907dd5ac1f8b559bf65ab477dfe0f0.tar.gz pleroma-c765fcbe7e907dd5ac1f8b559bf65ab477dfe0f0.zip |
Gun Connection Pool: successfully retry after reclaiming the pool
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/gun/connection_pool/worker_supervisor.ex | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/lib/pleroma/gun/connection_pool/worker_supervisor.ex b/lib/pleroma/gun/connection_pool/worker_supervisor.ex index eb83962d8..dabb15b08 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 + spawn(fn -> free_pool() end) + start_worker(opts, true) res -> res |