Error when sending messages to liveview processes
PaulOstazeski opened this issue · 2 comments
Hi! I heard about bandit on the ThinkingElixir podcast and wanted to give it a try. I found what I think might be a bug.
I am using bandit 0.6.7, thousand_island 0.5.15, phoenix 1.7.0-rc.2, elixir 1.14.0 and erlang 25.0.
I make a new phoenix project via mix archive.install hex phx_new 1.7.0-rc.2 ; mix phx.new foo
- then I replace plug_cowboy
with {:bandit, "~> 0.6.7"}
in hex.exs and add adapter: Bandit.PhoenixAdapter
in config/config.exs.
If I send any messages to a liveview process, the first time such a message is sent, I see the error (FunctionClauseError) no function clause matching in Bandit.HTTP1.Handler.handle_info/2
(more lines attached below). Subsequent messages do not repeat the same error. The liveview's handle_info
callback is invoked in both cases.
Example liveview code
def mount(_params, _session, socket) do
:timer.send_interval(1000, :tick)
{:ok, assign(socket}
end
def handle_info(:tick, socket) do
IO.inspect("tick happened")
{:noreply, socket}
end
Full error output:
[error] GenServer #PID<0.2882.0> terminating
** (FunctionClauseError) no function clause matching in Bandit.HTTP1.Handler.handle_info/2
(bandit 0.6.7) lib/thousand_island/handler.ex:5: Bandit.HTTP1.Handler.handle_info(:tick, {%ThousandIsland.Socket{socket: #Port<0.55>, transport_module: ThousandIsland.Transports.TCP, read_timeout: 15000}, %{handler_module: Bandit.HTTP1.Handler, plug: {Phoenix.Endpoint.SyncCodeReloadPlug, {FartWeb.Endpoint, []}}}})
(stdlib 4.0) gen_server.erl:1120: :gen_server.try_dispatch/4
(stdlib 4.0) gen_server.erl:1197: :gen_server.handle_msg/6
(stdlib 4.0) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message: :tick
State: {%ThousandIsland.Socket{socket: #Port<0.55>, transport_module: ThousandIsland.Transports.TCP, read_timeout: 15000}, %{handler_module: Bandit.HTTP1.Handler, plug: {Phoenix.Endpoint.SyncCodeReloadPlug, {FartWeb.Endpoint, []}}}}
tick happened
tick happened
tick happened
...
This is a simplified example, but it happens when sending messages "up" from a livecomponent to the surrounding liveview (via send(self(), ...)
, and when using pubsub to subscribe to a topic from a liveview.
Hahaha. I think the bug is in my code. Calling send
or subscribe
should only happen when connected?(socket)
is true. Disregard.