Phoenix 1.4 升级 - (函数子句错误)Phoenix.Socket.__terminate__/2 中没有函



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

任何见解都非常感谢!

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

从文件中,它需要呼叫中缺少的:inverse_channels字段。

因此,如果您尝试在调用中添加一个 channels_inverse(下面的第二行(字段(在 iex 中(,并在 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?

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

相关内容

  • 没有找到相关文章

最新更新