From a4139f28162f60c5a207b4fc7d3182aac2bb981b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Christopher=20Cot=C3=A9?= Date: Fri, 3 Dec 2021 15:08:10 -0500 Subject: [PATCH] handle failed lookups --- lib/router/realms/session.ex | 31 ++++++++++++++++++------------- lib/router/session.ex | 25 +++++++++++++++---------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/lib/router/realms/session.ex b/lib/router/realms/session.ex index 7f838d6..ce7402d 100644 --- a/lib/router/realms/session.ex +++ b/lib/router/realms/session.ex @@ -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 diff --git a/lib/router/session.ex b/lib/router/session.ex index 4c7cceb..66de4b5 100644 --- a/lib/router/session.ex +++ b/lib/router/session.ex @@ -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 -- 2.45.3