Gun Connection Pool: successfully retry after reclaiming the pool
This commit is contained in:
parent
1071632a50
commit
c765fcbe7e
1
changelog.d/gun_pool4.fix
Normal file
1
changelog.d/gun_pool4.fix
Normal file
@ -0,0 +1 @@
|
|||||||
|
Gun Connection Pool was not retrying to acquire a connection if the pool was full and stale connections were reclaimed
|
@ -5,6 +5,9 @@
|
|||||||
defmodule Pleroma.Gun.ConnectionPool.WorkerSupervisor do
|
defmodule Pleroma.Gun.ConnectionPool.WorkerSupervisor do
|
||||||
@moduledoc "Supervisor for pool workers. Does not do anything except enforce max connection limit"
|
@moduledoc "Supervisor for pool workers. Does not do anything except enforce max connection limit"
|
||||||
|
|
||||||
|
alias Pleroma.Config
|
||||||
|
alias Pleroma.Gun.ConnectionPool.Worker
|
||||||
|
|
||||||
use DynamicSupervisor
|
use DynamicSupervisor
|
||||||
|
|
||||||
def start_link(opts) do
|
def start_link(opts) do
|
||||||
@ -14,21 +17,28 @@ defmodule Pleroma.Gun.ConnectionPool.WorkerSupervisor do
|
|||||||
def init(_opts) do
|
def init(_opts) do
|
||||||
DynamicSupervisor.init(
|
DynamicSupervisor.init(
|
||||||
strategy: :one_for_one,
|
strategy: :one_for_one,
|
||||||
max_children: Pleroma.Config.get([:connections_pool, :max_connections])
|
max_children: Config.get([:connections_pool, :max_connections])
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def start_worker(opts, last_attempt \\ false) do
|
def start_worker(opts, last_attempt \\ false)
|
||||||
case DynamicSupervisor.start_child(__MODULE__, {Pleroma.Gun.ConnectionPool.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
|
def start_worker(opts, true) do
|
||||||
:telemetry.execute([:pleroma, :connection_pool, :provision_failure], %{opts: opts})
|
case DynamicSupervisor.start_child(__MODULE__, {Worker, opts}) do
|
||||||
{:error, :pool_full}
|
{:error, :max_children} ->
|
||||||
else
|
:telemetry.execute([:pleroma, :connection_pool, :provision_failure], %{opts: opts})
|
||||||
start_worker(opts, true)
|
{:error, :pool_full}
|
||||||
end
|
|
||||||
|
res ->
|
||||||
|
res
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def start_worker(opts, false) do
|
||||||
|
case DynamicSupervisor.start_child(__MODULE__, {Worker, opts}) do
|
||||||
|
{:error, :max_children} ->
|
||||||
|
spawn(fn -> free_pool() end)
|
||||||
|
start_worker(opts, true)
|
||||||
|
|
||||||
res ->
|
res ->
|
||||||
res
|
res
|
||||||
|
@ -46,7 +46,6 @@ defmodule Pleroma.Gun.ConnectionPoolTest do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@tag :erratic
|
|
||||||
test "connection limit is respected with concurrent requests" do
|
test "connection limit is respected with concurrent requests" do
|
||||||
clear_config([:connections_pool, :max_connections]) do
|
clear_config([:connections_pool, :max_connections]) do
|
||||||
clear_config([:connections_pool, :max_connections], 1)
|
clear_config([:connections_pool, :max_connections], 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user