diff options
| author | Mark Felder <feld@feld.me> | 2024-02-09 10:36:58 -0500 | 
|---|---|---|
| committer | Mark Felder <feld@feld.me> | 2024-02-09 10:48:40 -0500 | 
| commit | 0eca3e38ebd6c5b1e7135275959d984af7acfd26 (patch) | |
| tree | 29a00be925b6f08c0bd1cd0b75636674b7eb7dec | |
| parent | 72480e7b2fc19beaa8a0a524e8b1c83442debd01 (diff) | |
| download | pleroma-0eca3e38ebd6c5b1e7135275959d984af7acfd26.tar.gz pleroma-0eca3e38ebd6c5b1e7135275959d984af7acfd26.zip | |
Fix Gun connection supervisor logic error
This was recently changed to solve a Dialyzer error, but the replacement logic was faulty as "retry" would only be compared to :error and not have its truthiness evaluated.
The original logic was also faulty as it returned {:error, :pool_full} even retry was true. It never retried when the pool was full.
| -rw-r--r-- | changelog.d/gun_pool.fix | 1 | ||||
| -rw-r--r-- | lib/pleroma/gun/connection_pool/worker_supervisor.ex | 4 | 
2 files changed, 4 insertions, 1 deletions
| diff --git a/changelog.d/gun_pool.fix b/changelog.d/gun_pool.fix new file mode 100644 index 000000000..94ec9103d --- /dev/null +++ b/changelog.d/gun_pool.fix @@ -0,0 +1 @@ +Fix logic error in Gun connection pooling which prevented retries even when the worker was launched with retry = true diff --git a/lib/pleroma/gun/connection_pool/worker_supervisor.ex b/lib/pleroma/gun/connection_pool/worker_supervisor.ex index b2be4ff87..24ad61117 100644 --- a/lib/pleroma/gun/connection_pool/worker_supervisor.ex +++ b/lib/pleroma/gun/connection_pool/worker_supervisor.ex @@ -21,7 +21,9 @@ defmodule Pleroma.Gun.ConnectionPool.WorkerSupervisor do    def start_worker(opts, retry \\ false) do      case DynamicSupervisor.start_child(__MODULE__, {Pleroma.Gun.ConnectionPool.Worker, opts}) do        {:error, :max_children} -> -        if Enum.any?([retry, free_pool()], &match?(&1, :error)) do +        funs = [fn -> !retry 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 | 
