0

我最近将我的 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 中实现终止,但它没有改变任何东西。

非常感谢任何见解!

4

2 回答 2

2

看起来\__terminate__函数签名和传递给它的内容不匹配。

文件中,它需要: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?

于 2019-02-05T07:37:44.307 回答
0

想通了(这很愚蠢)......在我需要删除的每个频道模块中use Phoenix.Socket:/

于 2019-02-05T15:48:59.737 回答