Phoenix 1.4升级-(FunctionClauseError)Phoenix.Socket中没有匹配的函数子句。__terminate __ / 2

时间:2019-02-03 21:23:21

标签: elixir phoenix-framework phoenix-channels

我最近将Phoenix应用程序从1.3升级到了1.4。

一切都很棒,但是当我离开某个页面时,出现以下错误:

[error] GenServer #PID<0.509.0> terminating
** (FunctionClauseError) no function clause matching in Phoenix.Socket.__terminate__/2
    (phoenix) lib/phoenix/socket.ex:544: Phoenix.Socket.__terminate__({:shutdown, :closed}, %Phoenix.Socket{assigns: %{}, channel: MhrWeb.SearchChannel, channel_pid: #PID<0.509.0>, endpoint: MhrWeb.Endpoint, handler: MhrWeb.UserSocket, id: nil, join_ref: "2", joined: true, private: %{log_handle_in: :debug, log_join: :info}, pubsub_server: Mhr.PubSub, ref: nil, serializer: Phoenix.Socket.V2.JSONSerializer, topic: "search:query", transport: :websocket, transport_pid: #PID<0.497.0>})
    (stdlib) gen_server.erl:673: :gen_server.try_terminate/3
    (stdlib) gen_server.erl:858: :gen_server.terminate/10
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: {:"$gen_cast", :close}
State: %Phoenix.Socket{assigns: %{}, channel: MhrWeb.SearchChannel, channel_pid: #PID<0.509.0>, endpoint: MhrWeb.Endpoint, handler: MhrWeb.UserSocket, id: nil, join_ref: "2", joined: true, private: %{log_handle_in: :debug, log_join: :info}, pubsub_server: Mhr.PubSub, ref: nil, serializer: Phoenix.Socket.V2.JSONSerializer, topic: "search:query", transport: :websocket, transport_pid: #PID<0.497.0>}

我已经尝试在处理特定主题的user_socket.ex和search_channel.ex中实现终止,但是它没有任何改变。

非常感谢任何见识!

2 个答案:

答案 0 :(得分:2)

似乎\__terminate__函数签名和传递给它的内容不匹配。

the file中,它期望呼叫中的:inverse_channels字段在您的呼叫中丢失。

因此,如果您尝试在调用中(在iex中)添加channels_inverse(下面的第二行)字段,并在pid0变量中添加示例PID

Phoenix.Socket.__terminate__({:shutdown, :closed}, {
  %{channels_inverse: %{}}, # this is dummy data added!!

  %Phoenix.Socket{assigns: %{}, channel: MhrWeb.SearchChannel, 
    channel_pid: pid0, endpoint: MhrWeb.Endpoint, handler: MhrWeb.UserSocket, 
    id: nil, join_ref: "2", joined: true, private: %{log_handle_in: :debug, log_join: :info}, 
    pubsub_server: Mhr.PubSub, ref: nil, serializer: Phoenix.Socket.V2.JSONSerializer, 
    topic: "search:query", transport: :websocket, transport_pid: pid0}
})

函数子句错误消失

因此,您将不得不跟踪此函数调用的来源,而没有%{channels_inverse: %{}}来自。也许您与套接字相关的javascript文件未更新到phoenix 1.4?

答案 1 :(得分:0)

在我需要删除use Phoenix.Socket的每个频道模块中弄清楚了(很蠢)...:/