patreeceeo

patreeceeo

Ranch listener MyApp.Endpoint.HTTP had connection process started with :cowboy_clear:start_link/4 at ... exit with reason

My phoenix app starts up fine, but as soon as I modify any elixir source files the above error begins to occur repeatedly. This is the reason it gives:

{:undef, [{MusicJamGameWeb.RoomChannel, :child_spec, [{MusicJamGameWeb.Endpoint, {pid<0.1281.0>, reference<0.623636450.1826357254.163247>}}], }, {Phoenix.Channel.Server, :join, 4, [file: ‘lib/phoenix/channel/server.ex’, line: 24]}, {Phoenix.Socket, :handle_in, 4, [file: ‘lib/phoenix/socket.ex’, line: 598]}, {Phoenix.Endpoint.Cowboy2Handler, :websocket_handle, 2, [file: ‘lib/phoenix/endpoint/cowboy2_handler.ex’, line: 145]}, {:cowboy_websocket, :handler_call, 6, [file: ‘/home/patrick/Code/music_jam_game/deps/cowboy/src/cowboy_websocket.erl’, line: 528]}, {:cowboy_http, :loop, 1, [file: ‘/home/patrick/Code/music_jam_game/deps/cowboy/src/cowboy_http.erl’, line: 257]}, {:proc_lib, :init_p_do_apply, 3, [file: ‘proc_lib.erl’, line: 226]}]}

So far I’ve just been following the guide on using channels (Channels — Phoenix v1.8.8) trying to get a channel up and running. I’ll push my code to GH in case that helps. Also possibly unrelated but the messages pushed on to the channel by the JS are not being received in my handle_in callback. I’m stumped.

Marked As Solved

beepbeepbopbop

beepbeepbopbop

I’ve pulled your repo down as is and it fails, but once I add the channel module definition, it works as intended. In your reproduction repo, your channel module does not exist and any attempt to join a channel should fail. In fact, if you read your error message carefully, you can actually guess what it’s trying to do. Now, it does require some experience, but I can walk you through my thought process.

[error] Ranch listener MusicJamServerWeb.Endpoint.HTTP had connection process started with :cowboy_clear:start_link/4 at #PID<0.5779.0> exit with reason: {:undef, [{MusicJamServerWeb.RoomChannel, :child_spec, [{MusicJamServerWeb.Endpoint, {#PID<0.5779.0>, #Reference<0.3249608392.111935491.56526>}}], []}, {Phoenix.Channel.Server, :join, 4, [file: 'lib/phoenix/channel/server.ex', line: 24]}, {Phoenix.Socket, :handle_in, 4, [file: 'lib/phoenix/socket.ex', line: 598]}, {Phoenix.Endpoint.Cowboy2Handler, :websocket_handle, 2, [file: 'lib/phoenix/endpoint/cowboy2_handler.ex', line: 145]}, {:cowboy_websocket, :handler_call, 6, [file: '/home/patrick/Code/music_jam_server/deps/cowboy/src/cowboy_websocket.erl', line: 528]}, {:cowboy_http, :loop, 1, [file: '/home/patrick/Code/music_jam_server/deps/cowboy/src/cowboy_http.erl', line: 257]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 226]}]

There are two halves of these error that are important to us:

:undef, [{MusicJamServerWeb.RoomChannel, :child_spec, [{MusicJamServerWeb.Endpoint, {#PID<0.5779.0>, #Reference<0.3249608392.111935491.56526>}}], []},

and then every under it. What this looks like is a trace, specifically a function trace. You can tell since the output reads like a MFA (module-function-arguments). MFA are typically used with apply/3, so things like apply(String, :at, ["example", 2]) are used for somewhat dynamic calls. Now, take a look at first line:

{MusicJamServerWeb.RoomChannel, :child_spec, [{MusicJamServerWeb.Endpoint, {#PID<0.5779.0>, #Reference<0.3249608392.111935491.56526>}}]

This is definitely a MFA like structure, a module, a function atom and the leading arguments. So for one, if we assume that this is the case, the module MusicJamServerWeb.RoomChannel must exist, but it does not in your repository. Furthermore, the :child_spec function is critically important in Erlang; it defines the specification to start child processes. With that being said, we can check the Phoenix socket code for this behaviour: phoenix/lib/phoenix/channel/server.ex at v1.6 · phoenixframework/phoenix · GitHub

Here the channel is expected to have a function child_spec/1, but since the module is undefiined, you’ll run into the exact problem you have. This can easily be replicated here:

iex(2)> apply(DoesNotExist, :hello, [])
** (UndefinedFunctionError) function DoesNotExist.hello/0 is undefined (module DoesNotExist is not available)
    DoesNotExist.hello()

If you go back to the Phoenix code, it attempts to start the child process based off that child specification call, but since you’re trying to call a function that doesn’t exist, it outright fails.

Also Liked

beepbeepbopbop

beepbeepbopbop

Could be off but check your channel module name in GH: (https://github.com/patreeceeo/music_jam_server/blob/main/lib/music_jam_game_web/channels/room_channel.ex#L1)

HelloWeb.RoomChannel != MusicJamGameWeb.RoomChannel

The clue was the module name in user_socket.ex: MusicJamGameWeb.RoomChannel,.

beepbeepbopbop

beepbeepbopbop

Are you sure? I’ve pulled down your repository, updated room_channel.ex and the problem goes away.

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement