Connection pool: check that there actually is a result
authorrinpatch <rinpatch@sdf.org>
Wed, 6 May 2020 18:51:10 +0000 (21:51 +0300)
committerrinpatch <rinpatch@sdf.org>
Wed, 15 Jul 2020 12:17:27 +0000 (15:17 +0300)
Sometimes connections died before being released to the pool, resulting
in MatchErrors

lib/pleroma/gun/connection_pool.ex

index ed7ddff81102217dea51c297982356d063b2d406..0daf1da44bfed3dd2ec5bf6f12bf8dc0b9253cdd 100644 (file)
@@ -119,11 +119,17 @@ defmodule Pleroma.Gun.ConnectionPool do
   end
 
   def release_conn(conn_pid) do
-    [worker_pid] =
+    query_result =
       Registry.select(@registry, [
         {{:_, :"$1", {:"$2", :_, :_, :_}}, [{:==, :"$2", conn_pid}], [:"$1"]}
       ])
 
-    GenServer.cast(worker_pid, {:remove_client, self()})
+    case query_result do
+      [worker_pid] ->
+        GenServer.cast(worker_pid, {:remove_client, self()})
+
+      [] ->
+        :ok
+    end
   end
 end