]> Entropealabs - wampex_router.git/commitdiff
handle failed lookups
authorChristopher Coté <chris@entropealabs.com>
Fri, 3 Dec 2021 20:08:10 +0000 (15:08 -0500)
committerChristopher Coté <chris@entropealabs.com>
Fri, 3 Dec 2021 20:08:10 +0000 (15:08 -0500)
lib/router/realms/session.ex
lib/router/session.ex

index 7f838d6cfe21d32e9b69b7c0c204e11a7301f763..ce7402d91a126c1949035fd61cf8a30b97530cf5 100644 (file)
@@ -54,19 +54,24 @@ defmodule Wampex.Router.Realms.Session do
   end
 
   def unsubscribe(db, realm, {id, _from} = value, subscriptions) do
-    {_id, topic, wc} = sub = get_subscription(id, subscriptions)
-
-    key =
-      case wc do
-        true ->
-          get_wildcard_key(topic)
-
-        false ->
-          topic
-      end
-
-    ClusterKV.update(db, realm, key, value, :remove)
-    remove_val(sub, subscriptions)
+    case get_subscription(id, subscriptions) do
+      {_id, topic, wc} = sub ->
+        key =
+          case wc do
+            true ->
+              get_wildcard_key(topic)
+
+            false ->
+              topic
+          end
+
+        ClusterKV.update(db, realm, key, value, :remove)
+        remove_val(sub, subscriptions)
+
+      _ ->
+        Logger.error("Unable to unsubscribe #{id} not present in subscriptions: #{subscriptions}")
+        subscriptions
+    end
   end
 
   def subscriptions(db, realm, topic) do
index 4c7ccebeabf249a41480e7f5166cabebb093c9c8..66de4b587c0592a4ed09ab36db25963a09e1ac95 100644 (file)
@@ -515,16 +515,22 @@ defmodule Wampex.Router.Session do
           }
         } = data
       ) do
-    {call_id, _, {pid, node}} =
-      Enum.find(inv, fn
-        {_, %Invocation{request_id: ^id}, _} -> true
-        _ -> false
-      end)
+    case Enum.find(inv, fn
+           {_, %Invocation{request_id: ^id}, _} -> true
+           _ -> false
+         end) do
+      {call_id, _, {pid, node}} ->
+        send(
+          {proxy, node},
+          {%Result{request_id: call_id, arg_list: arg_l, arg_kw: arg_kw, details: opts}, pid}
+        )
 
-    send(
-      {proxy, node},
-      {%Result{request_id: call_id, arg_list: arg_l, arg_kw: arg_kw, details: opts}, pid}
-    )
+        Logger.info("Yield: #{realm} - #{id}")
+
+      _ ->
+        Logger.error("Unable to yield: #{id} not present in invocations: #{inspect(inv)}")
+        :ok
+    end
 
     inv =
       Enum.filter(inv, fn
@@ -532,7 +538,6 @@ defmodule Wampex.Router.Session do
         _ -> true
       end)
 
-    Logger.info("Yield: #{realm} - #{id}")
     {:ok, %SL{data | data: %Sess{data.data | invocations: inv, yield: nil}}, [{:next_event, :internal, :transition}]}
   end