1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Gun.ConnectionPool.WorkerSupervisor do
6 @moduledoc "Supervisor for pool workers. Does not do anything except enforce max connection limit"
10 def start_link(opts) do
11 DynamicSupervisor.start_link(__MODULE__, opts, name: __MODULE__)
15 DynamicSupervisor.init(
16 strategy: :one_for_one,
17 max_children: Pleroma.Config.get([:connections_pool, :max_connections])
21 def start_worker(opts, retry \\ false) do
22 case DynamicSupervisor.start_child(__MODULE__, {Pleroma.Gun.ConnectionPool.Worker, opts}) do
23 {:error, :max_children} ->
24 if retry or free_pool() == :error do
25 :telemetry.execute([:pleroma, :connection_pool, :provision_failure], %{opts: opts})
28 start_worker(opts, true)
37 wait_for_reclaimer_finish(Pleroma.Gun.ConnectionPool.Reclaimer.start_monitor())
40 defp wait_for_reclaimer_finish({pid, mon}) do
42 {:DOWN, ^mon, :process, ^pid, :no_unused_conns} ->
45 {:DOWN, ^mon, :process, ^pid, :normal} ->