]> Entropealabs - wampex.git/commitdiff
invocations couldbe gone by the time we yield, also handle ping and unknown websocket...
authorChristopher <chris@entropealabs.com>
Tue, 17 Mar 2020 19:27:16 +0000 (14:27 -0500)
committerChristopher <chris@entropealabs.com>
Tue, 17 Mar 2020 19:27:16 +0000 (14:27 -0500)
lib/router/session.ex
lib/router/transports/web_socket.ex

index f053c7ab927926f6e97ad3d7b55f010aca07830b..d290095c4419d6bd430a895907b8453dd845e725 100644 (file)
@@ -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
index 88521d7613a0130399463115247acdf31ef02aaa..73e1b7a7f610931153396a002f9ee38a2c66590b 100644 (file)
@@ -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}