From: Christopher Date: Tue, 17 Mar 2020 19:27:16 +0000 (-0500) Subject: invocations couldbe gone by the time we yield, also handle ping and unknown websocket... X-Git-Url: http://git.entropealabs.com/?a=commitdiff_plain;h=105aa8241313d903a745a87e8e39cc9e54f644f6;p=wampex.git invocations couldbe gone by the time we yield, also handle ping and unknown websocket messages --- diff --git a/lib/router/session.ex b/lib/router/session.ex index f053c7a..d290095 100644 --- a/lib/router/session.ex +++ b/lib/router/session.ex @@ -482,16 +482,19 @@ defmodule Wampex.Router.Session do %SL{data: %Sess{proxy: proxy, invocations: inv, yield: {:yield, id, dets, arg_l, arg_kw}}} = data ) do - {call_id, _, {pid, node}} = - Enum.find(inv, fn - {_, %Invocation{request_id: ^id}, _} -> true - _ -> false - end) - - send( - {proxy, node}, - {%Result{request_id: call_id, arg_list: arg_l, arg_kw: arg_kw, options: dets}, pid} - ) + 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, options: dets}, pid} + ) + + nil -> + :noop + end inv = Enum.filter(inv, fn diff --git a/lib/router/transports/web_socket.ex b/lib/router/transports/web_socket.ex index 88521d7..73e1b7a 100644 --- a/lib/router/transports/web_socket.ex +++ b/lib/router/transports/web_socket.ex @@ -39,6 +39,17 @@ defmodule Wampex.Router.Transports.WebSocket do {:ok, state, :hibernate} end + @impl true + def websocket_handle(:ping, state) do + {:pong, state, :hibernate} + end + + @impl true + def websocket_handle(unknown, state) do + Logger.warn("Unknown websocket frame #{inspect(unknown)}") + {:ok, state, :hibernate} + end + @impl true def websocket_info({:send_request, message}, %WebSocket{serializer: s} = state) do {[{s.data_type(), s.serialize!(message)}], state, :hibernate}