Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[error] GenServer #PID<0.397.0> terminating
** (RuntimeError) Expected handle_info to return one of:
{:noreply, Socket.t} |
{:noreply, Socket.t, timeout | :hibernate} |
{:stop, reason :: term, Socket.t} |
got {:no_reply, %Phoenix.Socket{assigns: %{}, channel: Chat.MetadataChannel, channel_pid: #PID<0.397.0>, endpoint: Chat.Endpoint, handler: Chat.UserSocket, id: nil, join_ref: "1", joined: true, private: %{log_handle_in: :debug, log_join: :info}, pubsub_server: Chat.PubSub, ref: nil, serializer: Phoenix.Socket.V1.JSONSerializer, topic: "metadata", transport: :websocket, transport_pid: #PID<0.394.0>}}
(phoenix) lib/phoenix/channel/server.ex:409: Phoenix.Channel.Server.handle_result/2
(stdlib) gen_server.erl:637: :gen_server.try_dispatch/4
(stdlib) gen_server.erl:711: :gen_server.handle_msg/6
(stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: {:redix_pubsub, #PID<0.398.0>, #Reference<0.2142624301.3746824197.172038>, :message, %{channel: "metadata", payload: "hello"}}
State: %Phoenix.Socket{assigns: %{}, channel: Chat.MetadataChannel, channel_pid: #PID<0.397.0>, endpoint: Chat.Endpoint, handler: Chat.UserSocket, id: nil, join_ref: "1", joined: true, private: %{log_handle_in: :debug, log_join: :info}, pubsub_server: Chat.PubSub, ref: nil, serializer: Phoenix.Socket.V1.JSONSerializer, topic: "metadata", transport: :websocket, transport_pid: #PID<0.394.0>}
defmodule Chat.MetadataChannel do
use Phoenix.Channel
require Logger
def join("metadata", message, socket) do
{:ok, pubsub} = Redix.PubSub.start_link()
Redix.PubSub.subscribe(pubsub, "metadata", self())
{:ok, socket}
end
# Avoid throwing an error when a subscribed message enters the channel
def handle_info({:redix_pubsub, _redix_pid, _ref, :subscribed, _}, socket) do
{:noreply, socket}
end
# Handle the message coming from the Redis PubSub channel
def handle_info({:redix_pubsub, _redix_id, _ref, :message, message}, socket) do
Logger.debug "got message from pubsub #{message["payload"]} on #{message["channel"]}"
# do something with the message
# Push the message back to the user over the channel topic
# This assumes the message is already in a map
broadcast! socket, "metadata", message
{:no_reply, socket}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.