Request limiter setup: consider {:error, :existing} a success
authorrinpatch <rinpatch@sdf.org>
Tue, 30 Jun 2020 15:35:15 +0000 (18:35 +0300)
committerrinpatch <rinpatch@sdf.org>
Wed, 15 Jul 2020 12:26:35 +0000 (15:26 +0300)
When the application restarts (which happens after certain config
changes), the limiters are not destroyed, so `ConcurrentLimiter.new`
will produce {:error, :existing}

lib/pleroma/http/adapter_helper/gun.ex

index 07aaed7f6e26e63bcf6b904f8e6334afdff8b259..b8c4cc59c9b738bebe5008cce448ac8d7e98042d 100644 (file)
@@ -88,11 +88,17 @@ defmodule Pleroma.HTTP.AdapterHelper.Gun do
       max_running = Keyword.get(opts, :size, 50)
       max_waiting = Keyword.get(opts, :max_waiting, 10)
 
-      :ok =
+      result =
         ConcurrentLimiter.new(:"#{@prefix}.#{name}", max_running, max_waiting,
           wait: wait,
           max_retries: retries
         )
+
+      case result do
+        :ok -> :ok
+        {:error, :existing} -> :ok
+        e -> raise e
+      end
     end)
 
     :ok